repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
locomotivemtl/charcoal-property | src/Charcoal/Property/StringProperty.php | StringProperty.validateRegexp | public function validateRegexp()
{
$val = $this->val();
$regexp = $this->regexp();
if ($regexp == '') {
return true;
}
$valid = !!preg_match($regexp, $val);
if (!$valid) {
$this->validator()->error('Regexp error', 'regexp');
}
return $valid;
} | php | public function validateRegexp()
{
$val = $this->val();
$regexp = $this->regexp();
if ($regexp == '') {
return true;
}
$valid = !!preg_match($regexp, $val);
if (!$valid) {
$this->validator()->error('Regexp error', 'regexp');
}
return $valid;
} | [
"public",
"function",
"validateRegexp",
"(",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"val",
"(",
")",
";",
"$",
"regexp",
"=",
"$",
"this",
"->",
"regexp",
"(",
")",
";",
"if",
"(",
"$",
"regexp",
"==",
"''",
")",
"{",
"return",
"true",
"... | Validate if the property's value matches the regular expression.
@return boolean | [
"Validate",
"if",
"the",
"property",
"s",
"value",
"matches",
"the",
"regular",
"expression",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/StringProperty.php#L418-L433 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/StringProperty.php | StringProperty.validateAllowEmpty | public function validateAllowEmpty()
{
$val = $this->val();
if (($val === null || $val === '') && !$this->allowEmpty()) {
return false;
} else {
return true;
}
} | php | public function validateAllowEmpty()
{
$val = $this->val();
if (($val === null || $val === '') && !$this->allowEmpty()) {
return false;
} else {
return true;
}
} | [
"public",
"function",
"validateAllowEmpty",
"(",
")",
"{",
"$",
"val",
"=",
"$",
"this",
"->",
"val",
"(",
")",
";",
"if",
"(",
"(",
"$",
"val",
"===",
"null",
"||",
"$",
"val",
"===",
"''",
")",
"&&",
"!",
"$",
"this",
"->",
"allowEmpty",
"(",
... | Validate if the property's value is allowed to be empty.
@return boolean | [
"Validate",
"if",
"the",
"property",
"s",
"value",
"is",
"allowed",
"to",
"be",
"empty",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/StringProperty.php#L440-L449 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/StringProperty.php | StringProperty.valLabel | protected function valLabel($val, $lang = null)
{
if (is_string($val) && $this->hasChoice($val)) {
$choice = $this->choice($val);
return $this->l10nVal($choice['label'], $lang);
} else {
return $val;
}
} | php | protected function valLabel($val, $lang = null)
{
if (is_string($val) && $this->hasChoice($val)) {
$choice = $this->choice($val);
return $this->l10nVal($choice['label'], $lang);
} else {
return $val;
}
} | [
"protected",
"function",
"valLabel",
"(",
"$",
"val",
",",
"$",
"lang",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"val",
")",
"&&",
"$",
"this",
"->",
"hasChoice",
"(",
"$",
"val",
")",
")",
"{",
"$",
"choice",
"=",
"$",
"this",
... | Attempts to return the label for a given choice.
@param string $val The value to retrieve the label of.
@param mixed $lang The language to return the label in.
@return string Returns the label. Otherwise, returns the raw value. | [
"Attempts",
"to",
"return",
"the",
"label",
"for",
"a",
"given",
"choice",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/StringProperty.php#L511-L519 | train |
ethical-jobs/ethical-jobs-foundation-php | src/Utils/Arrays.php | Arrays.expandDotNotationKeys | public static function expandDotNotationKeys(Array $array)
{
$result = [];
foreach ($array as $key => $value) {
array_set($result, $key, $value);
}
return $result;
} | php | public static function expandDotNotationKeys(Array $array)
{
$result = [];
foreach ($array as $key => $value) {
array_set($result, $key, $value);
}
return $result;
} | [
"public",
"static",
"function",
"expandDotNotationKeys",
"(",
"Array",
"$",
"array",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"array_set",
"(",
"$",
"result",
",",
"$",... | Expands arrays with keys that have dot notation
@param Array $array
@return Array | [
"Expands",
"arrays",
"with",
"keys",
"that",
"have",
"dot",
"notation"
] | 35dafc2172dc8ba44c0ace4a58a7c0a9b63455a8 | https://github.com/ethical-jobs/ethical-jobs-foundation-php/blob/35dafc2172dc8ba44c0ace4a58a7c0a9b63455a8/src/Utils/Arrays.php#L20-L29 | train |
975L/IncludeLibraryBundle | Twig/IncludeLibraryLink.php | IncludeLibraryLink.Link | public function Link($name, $type, $version = 'latest')
{
$type = strtolower($type);
//Gets data
$data = $this->includeLibraryService->getData($name, $type, $version);
//Returns the href or src part
if (null !== $data) {
return 'css' == $type ? $data['href'] : $data['src'];
}
//Throws an error if not found
throw new Error('The Library "' . $name . ' (' . $type . ') version ' . $version . '" requested via "inc_link()" was not found. Please check name and supported library/versions.');
} | php | public function Link($name, $type, $version = 'latest')
{
$type = strtolower($type);
//Gets data
$data = $this->includeLibraryService->getData($name, $type, $version);
//Returns the href or src part
if (null !== $data) {
return 'css' == $type ? $data['href'] : $data['src'];
}
//Throws an error if not found
throw new Error('The Library "' . $name . ' (' . $type . ') version ' . $version . '" requested via "inc_link()" was not found. Please check name and supported library/versions.');
} | [
"public",
"function",
"Link",
"(",
"$",
"name",
",",
"$",
"type",
",",
"$",
"version",
"=",
"'latest'",
")",
"{",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"type",
")",
";",
"//Gets data",
"$",
"data",
"=",
"$",
"this",
"->",
"includeLibraryService",
... | Returns the link of the requested library
@return string
@throws Error | [
"Returns",
"the",
"link",
"of",
"the",
"requested",
"library"
] | 74f9140551d6f20c1308213c4c142f7fff43eb52 | https://github.com/975L/IncludeLibraryBundle/blob/74f9140551d6f20c1308213c4c142f7fff43eb52/Twig/IncludeLibraryLink.php#L50-L64 | train |
cmsgears/module-core | common/config/CoreProperties.php | CoreProperties.getRootUrl | public function getRootUrl( $admin = false ) {
if( $admin ) {
return $this->properties[ self::PROP_ADMIN_URL ] . \Yii::getAlias( '@web' ) ;
}
return $this->properties[ self::PROP_SITE_URL ] . \Yii::getAlias( '@web' ) ;
} | php | public function getRootUrl( $admin = false ) {
if( $admin ) {
return $this->properties[ self::PROP_ADMIN_URL ] . \Yii::getAlias( '@web' ) ;
}
return $this->properties[ self::PROP_SITE_URL ] . \Yii::getAlias( '@web' ) ;
} | [
"public",
"function",
"getRootUrl",
"(",
"$",
"admin",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"admin",
")",
"{",
"return",
"$",
"this",
"->",
"properties",
"[",
"self",
"::",
"PROP_ADMIN_URL",
"]",
".",
"\\",
"Yii",
"::",
"getAlias",
"(",
"'@web'",
... | Returns the root URL for the app | [
"Returns",
"the",
"root",
"URL",
"for",
"the",
"app"
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/config/CoreProperties.php#L290-L298 | train |
phPoirot/Std | src/Type/StdString.php | StdString.stripPrefix | function stripPrefix($prefix)
{
$key = (string) $this;
if (substr($key, 0, strlen($prefix)) == $prefix)
$key = substr($key, strlen($prefix));
return new self($key);
} | php | function stripPrefix($prefix)
{
$key = (string) $this;
if (substr($key, 0, strlen($prefix)) == $prefix)
$key = substr($key, strlen($prefix));
return new self($key);
} | [
"function",
"stripPrefix",
"(",
"$",
"prefix",
")",
"{",
"$",
"key",
"=",
"(",
"string",
")",
"$",
"this",
";",
"if",
"(",
"substr",
"(",
"$",
"key",
",",
"0",
",",
"strlen",
"(",
"$",
"prefix",
")",
")",
"==",
"$",
"prefix",
")",
"$",
"key",
... | Remove a prefix string from the beginning of a string
@param string $prefix
@return StdString | [
"Remove",
"a",
"prefix",
"string",
"from",
"the",
"beginning",
"of",
"a",
"string"
] | 67883b1b1dd2cea80fec3d98a199c403b8a23b4d | https://github.com/phPoirot/Std/blob/67883b1b1dd2cea80fec3d98a199c403b8a23b4d/src/Type/StdString.php#L122-L130 | train |
phPoirot/Std | src/Type/StdString.php | StdString.slugify | function slugify()
{
$text = (string) $this;
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// trim
$text = trim($text, '-');
// remove duplicate -
$text = preg_replace('~-+~', '-', $text);
// lowercase
$text = strtolower($text);
if (empty($text))
return 'n-a';
return new self($text);
} | php | function slugify()
{
$text = (string) $this;
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// trim
$text = trim($text, '-');
// remove duplicate -
$text = preg_replace('~-+~', '-', $text);
// lowercase
$text = strtolower($text);
if (empty($text))
return 'n-a';
return new self($text);
} | [
"function",
"slugify",
"(",
")",
"{",
"$",
"text",
"=",
"(",
"string",
")",
"$",
"this",
";",
"// replace non letter or digits by -",
"$",
"text",
"=",
"preg_replace",
"(",
"'~[^\\pL\\d]+~u'",
",",
"'-'",
",",
"$",
"text",
")",
";",
"// transliterate",
"$",
... | Slugify Input Text
@return StdString | [
"Slugify",
"Input",
"Text"
] | 67883b1b1dd2cea80fec3d98a199c403b8a23b4d | https://github.com/phPoirot/Std/blob/67883b1b1dd2cea80fec3d98a199c403b8a23b4d/src/Type/StdString.php#L137-L163 | train |
phPoirot/Std | src/Type/StdString.php | StdString.PascalCase | function PascalCase()
{
$key = (string) $this;
## prefix and postfix __ remains; like: __this__
$pos = 'prefix';
$prefix = '';
$posfix = '';
for ($i = 0; $i <= strlen($key)-1; $i++) {
if ($key[$i] == '_')
$$pos.='_';
else {
$posfix = ''; // reset posix, _ may found within string
$pos = 'posfix';
}
}
$r = str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
$r = $prefix.$r.$posfix;
return new self($r);
} | php | function PascalCase()
{
$key = (string) $this;
## prefix and postfix __ remains; like: __this__
$pos = 'prefix';
$prefix = '';
$posfix = '';
for ($i = 0; $i <= strlen($key)-1; $i++) {
if ($key[$i] == '_')
$$pos.='_';
else {
$posfix = ''; // reset posix, _ may found within string
$pos = 'posfix';
}
}
$r = str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
$r = $prefix.$r.$posfix;
return new self($r);
} | [
"function",
"PascalCase",
"(",
")",
"{",
"$",
"key",
"=",
"(",
"string",
")",
"$",
"this",
";",
"## prefix and postfix __ remains; like: __this__",
"$",
"pos",
"=",
"'prefix'",
";",
"$",
"prefix",
"=",
"''",
";",
"$",
"posfix",
"=",
"''",
";",
"for",
"("... | Sanitize Underscore To Camelcase
@return StdString | [
"Sanitize",
"Underscore",
"To",
"Camelcase"
] | 67883b1b1dd2cea80fec3d98a199c403b8a23b4d | https://github.com/phPoirot/Std/blob/67883b1b1dd2cea80fec3d98a199c403b8a23b4d/src/Type/StdString.php#L181-L202 | train |
phPoirot/Std | src/Type/StdString.php | StdString.under_score | function under_score()
{
$key = (string) $this;
$output = strtolower(preg_replace(array('/([a-z\d])([A-Z])/', '/([^_])([A-Z][a-z])/'), '$1_$2', $key));
return new self($output);
} | php | function under_score()
{
$key = (string) $this;
$output = strtolower(preg_replace(array('/([a-z\d])([A-Z])/', '/([^_])([A-Z][a-z])/'), '$1_$2', $key));
return new self($output);
} | [
"function",
"under_score",
"(",
")",
"{",
"$",
"key",
"=",
"(",
"string",
")",
"$",
"this",
";",
"$",
"output",
"=",
"strtolower",
"(",
"preg_replace",
"(",
"array",
"(",
"'/([a-z\\d])([A-Z])/'",
",",
"'/([^_])([A-Z][a-z])/'",
")",
",",
"'$1_$2'",
",",
"$"... | Sanitize CamelCase To under_score
@return StdString | [
"Sanitize",
"CamelCase",
"To",
"under_score"
] | 67883b1b1dd2cea80fec3d98a199c403b8a23b4d | https://github.com/phPoirot/Std/blob/67883b1b1dd2cea80fec3d98a199c403b8a23b4d/src/Type/StdString.php#L209-L216 | train |
phPoirot/Std | src/Type/StdString.php | StdString.isUTF8 | function isUTF8()
{
$string = (string) $this;
if (function_exists('utf8_decode'))
$decodedStr = strlen(utf8_decode($string));
elseif (function_exists('mb_convert_encoding'))
$decodedStr = strlen(utf8_decode($string));
else
$decodedStr = $string;
return strlen($string) != strlen($decodedStr);
} | php | function isUTF8()
{
$string = (string) $this;
if (function_exists('utf8_decode'))
$decodedStr = strlen(utf8_decode($string));
elseif (function_exists('mb_convert_encoding'))
$decodedStr = strlen(utf8_decode($string));
else
$decodedStr = $string;
return strlen($string) != strlen($decodedStr);
} | [
"function",
"isUTF8",
"(",
")",
"{",
"$",
"string",
"=",
"(",
"string",
")",
"$",
"this",
";",
"if",
"(",
"function_exists",
"(",
"'utf8_decode'",
")",
")",
"$",
"decodedStr",
"=",
"strlen",
"(",
"utf8_decode",
"(",
"$",
"string",
")",
")",
";",
"els... | Is Contain UTF-8 Encoding?
@return bool | [
"Is",
"Contain",
"UTF",
"-",
"8",
"Encoding?"
] | 67883b1b1dd2cea80fec3d98a199c403b8a23b4d | https://github.com/phPoirot/Std/blob/67883b1b1dd2cea80fec3d98a199c403b8a23b4d/src/Type/StdString.php#L223-L235 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/Middleware/CacheMiddleware.php | CacheMiddleware.cacheKeyFromRequest | private function cacheKeyFromRequest(RequestInterface $request)
{
$uri = $request->getUri();
$queryStr = $uri->getQuery();
if (!empty($queryStr)) {
$queryArr = [];
parse_str($queryStr, $queryArr);
$queryArr = $this->parseIgnoredParams($queryArr);
$queryStr = http_build_query($queryArr);
$uri = $uri->withQuery($queryStr);
}
$cacheKey = 'request/' . $request->getMethod() . '/' . md5((string)$uri);
return $cacheKey;
} | php | private function cacheKeyFromRequest(RequestInterface $request)
{
$uri = $request->getUri();
$queryStr = $uri->getQuery();
if (!empty($queryStr)) {
$queryArr = [];
parse_str($queryStr, $queryArr);
$queryArr = $this->parseIgnoredParams($queryArr);
$queryStr = http_build_query($queryArr);
$uri = $uri->withQuery($queryStr);
}
$cacheKey = 'request/' . $request->getMethod() . '/' . md5((string)$uri);
return $cacheKey;
} | [
"private",
"function",
"cacheKeyFromRequest",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"$",
"uri",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
";",
"$",
"queryStr",
"=",
"$",
"uri",
"->",
"getQuery",
"(",
")",
";",
"if",
"(",
"!",
"empty",... | Generate the cache key from the HTTP request.
@param RequestInterface $request The PSR-7 HTTP request.
@return string | [
"Generate",
"the",
"cache",
"key",
"from",
"the",
"HTTP",
"request",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/Middleware/CacheMiddleware.php#L251-L269 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/Middleware/CacheMiddleware.php | CacheMiddleware.isSkipCache | private function isSkipCache(RequestInterface $request)
{
if (isset($this->skipCache['session_vars'])) {
$skip = $this->skipCache['session_vars'];
if (!empty($skip)) {
if (!session_id()) {
session_cache_limiter(false);
session_start();
}
if (array_intersect_key($_SESSION, array_flip($skip))) {
return true;
}
}
}
return false;
} | php | private function isSkipCache(RequestInterface $request)
{
if (isset($this->skipCache['session_vars'])) {
$skip = $this->skipCache['session_vars'];
if (!empty($skip)) {
if (!session_id()) {
session_cache_limiter(false);
session_start();
}
if (array_intersect_key($_SESSION, array_flip($skip))) {
return true;
}
}
}
return false;
} | [
"private",
"function",
"isSkipCache",
"(",
"RequestInterface",
"$",
"request",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"skipCache",
"[",
"'session_vars'",
"]",
")",
")",
"{",
"$",
"skip",
"=",
"$",
"this",
"->",
"skipCache",
"[",
"'session_... | Determine if the HTTP request method matches the accepted choices.
@param RequestInterface $request The PSR-7 HTTP request.
@return boolean | [
"Determine",
"if",
"the",
"HTTP",
"request",
"method",
"matches",
"the",
"accepted",
"choices",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/Middleware/CacheMiddleware.php#L288-L306 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/Middleware/CacheMiddleware.php | CacheMiddleware.isPathIncluded | private function isPathIncluded($path)
{
if ($this->includedPath === '*') {
return true;
}
if (empty($this->includedPath) && !is_numeric($this->includedPath)) {
return false;
}
foreach ((array)$this->includedPath as $included) {
if (preg_match('@' . $included . '@', $path)) {
return true;
}
}
return false;
} | php | private function isPathIncluded($path)
{
if ($this->includedPath === '*') {
return true;
}
if (empty($this->includedPath) && !is_numeric($this->includedPath)) {
return false;
}
foreach ((array)$this->includedPath as $included) {
if (preg_match('@' . $included . '@', $path)) {
return true;
}
}
return false;
} | [
"private",
"function",
"isPathIncluded",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"includedPath",
"===",
"'*'",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"includedPath",
")",
"&&",
"!",
"is_num... | Determine if the request should be cached based on the URI path.
@param string $path The request path (route) to verify.
@return boolean | [
"Determine",
"if",
"the",
"request",
"should",
"be",
"cached",
"based",
"on",
"the",
"URI",
"path",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/Middleware/CacheMiddleware.php#L325-L342 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/Middleware/CacheMiddleware.php | CacheMiddleware.isPathExcluded | private function isPathExcluded($path)
{
if ($this->excludedPath === '*') {
return true;
}
if (empty($this->excludedPath) && !is_numeric($this->excludedPath)) {
return false;
}
foreach ((array)$this->excludedPath as $excluded) {
if (preg_match('@' . $excluded . '@', $path)) {
return true;
}
}
return false;
} | php | private function isPathExcluded($path)
{
if ($this->excludedPath === '*') {
return true;
}
if (empty($this->excludedPath) && !is_numeric($this->excludedPath)) {
return false;
}
foreach ((array)$this->excludedPath as $excluded) {
if (preg_match('@' . $excluded . '@', $path)) {
return true;
}
}
return false;
} | [
"private",
"function",
"isPathExcluded",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"excludedPath",
"===",
"'*'",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"excludedPath",
")",
"&&",
"!",
"is_num... | Determine if the request should NOT be cached based on the URI path.
@param string $path The request path (route) to verify.
@return boolean | [
"Determine",
"if",
"the",
"request",
"should",
"NOT",
"be",
"cached",
"based",
"on",
"the",
"URI",
"path",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/Middleware/CacheMiddleware.php#L350-L367 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/Middleware/CacheMiddleware.php | CacheMiddleware.isQueryIncluded | private function isQueryIncluded(array $queryParams)
{
if (empty($queryParams)) {
return true;
}
if ($this->includedQuery === '*') {
return true;
}
if (empty($this->includedQuery) && !is_numeric($this->includedQuery)) {
return false;
}
$includedParams = array_intersect_key($queryParams, array_flip((array)$this->includedQuery));
return (count($includedParams) > 0);
} | php | private function isQueryIncluded(array $queryParams)
{
if (empty($queryParams)) {
return true;
}
if ($this->includedQuery === '*') {
return true;
}
if (empty($this->includedQuery) && !is_numeric($this->includedQuery)) {
return false;
}
$includedParams = array_intersect_key($queryParams, array_flip((array)$this->includedQuery));
return (count($includedParams) > 0);
} | [
"private",
"function",
"isQueryIncluded",
"(",
"array",
"$",
"queryParams",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"queryParams",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"includedQuery",
"===",
"'*'",
")",
"{",
"return... | Determine if the request should be cached based on the URI query.
@param array $queryParams The query parameters to verify.
@return boolean | [
"Determine",
"if",
"the",
"request",
"should",
"be",
"cached",
"based",
"on",
"the",
"URI",
"query",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/Middleware/CacheMiddleware.php#L375-L391 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/Middleware/CacheMiddleware.php | CacheMiddleware.isQueryExcluded | private function isQueryExcluded(array $queryParams)
{
if (empty($queryParams)) {
return false;
}
if ($this->excludedQuery === '*') {
return true;
}
if (empty($this->excludedQuery) && !is_numeric($this->excludedQuery)) {
return false;
}
$excludedParams = array_intersect_key($queryParams, array_flip((array)$this->excludedQuery));
return (count($excludedParams) > 0);
} | php | private function isQueryExcluded(array $queryParams)
{
if (empty($queryParams)) {
return false;
}
if ($this->excludedQuery === '*') {
return true;
}
if (empty($this->excludedQuery) && !is_numeric($this->excludedQuery)) {
return false;
}
$excludedParams = array_intersect_key($queryParams, array_flip((array)$this->excludedQuery));
return (count($excludedParams) > 0);
} | [
"private",
"function",
"isQueryExcluded",
"(",
"array",
"$",
"queryParams",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"queryParams",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"excludedQuery",
"===",
"'*'",
")",
"{",
"retur... | Determine if the request should NOT be cached based on the URI query.
@param array $queryParams The query parameters to verify.
@return boolean | [
"Determine",
"if",
"the",
"request",
"should",
"NOT",
"be",
"cached",
"based",
"on",
"the",
"URI",
"query",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/Middleware/CacheMiddleware.php#L399-L415 | train |
locomotivemtl/charcoal-cache | src/Charcoal/Cache/Middleware/CacheMiddleware.php | CacheMiddleware.parseIgnoredParams | private function parseIgnoredParams(array $queryParams)
{
if (empty($queryParams)) {
return $queryParams;
}
if ($this->ignoredQuery === '*') {
if ($this->includedQuery === '*') {
return $queryParams;
}
if (empty($this->includedQuery) && !is_numeric($this->includedQuery)) {
return [];
}
return array_intersect_key($queryParams, array_flip((array)$this->includedQuery));
}
if (empty($this->ignoredQuery) && !is_numeric($this->ignoredQuery)) {
return $queryParams;
}
return array_diff_key($queryParams, array_flip((array)$this->ignoredQuery));
} | php | private function parseIgnoredParams(array $queryParams)
{
if (empty($queryParams)) {
return $queryParams;
}
if ($this->ignoredQuery === '*') {
if ($this->includedQuery === '*') {
return $queryParams;
}
if (empty($this->includedQuery) && !is_numeric($this->includedQuery)) {
return [];
}
return array_intersect_key($queryParams, array_flip((array)$this->includedQuery));
}
if (empty($this->ignoredQuery) && !is_numeric($this->ignoredQuery)) {
return $queryParams;
}
return array_diff_key($queryParams, array_flip((array)$this->ignoredQuery));
} | [
"private",
"function",
"parseIgnoredParams",
"(",
"array",
"$",
"queryParams",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"queryParams",
")",
")",
"{",
"return",
"$",
"queryParams",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"ignoredQuery",
"===",
"'*'",
")",
... | Returns the query parameters that are NOT ignored.
@param array $queryParams The query parameters to filter.
@return array | [
"Returns",
"the",
"query",
"parameters",
"that",
"are",
"NOT",
"ignored",
"."
] | 38d04f6f21c6a826c28e08a5ac48b02c37e8da85 | https://github.com/locomotivemtl/charcoal-cache/blob/38d04f6f21c6a826c28e08a5ac48b02c37e8da85/src/Charcoal/Cache/Middleware/CacheMiddleware.php#L423-L446 | train |
phPoirot/Std | src/ErrorStack.php | ErrorStack.hasErrorAccrued | static function hasErrorAccrued()
{
if (!self::hasHandling())
return false;
$stack = self::$_STACK[self::getStackNum()-1];
return $stack['has_handled_error'];
} | php | static function hasErrorAccrued()
{
if (!self::hasHandling())
return false;
$stack = self::$_STACK[self::getStackNum()-1];
return $stack['has_handled_error'];
} | [
"static",
"function",
"hasErrorAccrued",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"hasHandling",
"(",
")",
")",
"return",
"false",
";",
"$",
"stack",
"=",
"self",
"::",
"$",
"_STACK",
"[",
"self",
"::",
"getStackNum",
"(",
")",
"-",
"1",
"]",
"... | Get Current Accrued Error If Has
@return false|\Exception|\ErrorException | [
"Get",
"Current",
"Accrued",
"Error",
"If",
"Has"
] | 67883b1b1dd2cea80fec3d98a199c403b8a23b4d | https://github.com/phPoirot/Std/blob/67883b1b1dd2cea80fec3d98a199c403b8a23b4d/src/ErrorStack.php#L174-L181 | train |
phPoirot/Std | src/ErrorStack.php | ErrorStack.handleDone | static function handleDone()
{
$return = null;
if (!self::hasHandling())
## there is no error
return $return;
$stack = array_pop(self::$_STACK);
if ($stack['has_handled_error'])
$return = $stack['has_handled_error'];
# restore error handler
(($stack['error_type']) === self::ERR_TYP_ERROR)
? restore_error_handler()
: restore_exception_handler()
;
return $return;
} | php | static function handleDone()
{
$return = null;
if (!self::hasHandling())
## there is no error
return $return;
$stack = array_pop(self::$_STACK);
if ($stack['has_handled_error'])
$return = $stack['has_handled_error'];
# restore error handler
(($stack['error_type']) === self::ERR_TYP_ERROR)
? restore_error_handler()
: restore_exception_handler()
;
return $return;
} | [
"static",
"function",
"handleDone",
"(",
")",
"{",
"$",
"return",
"=",
"null",
";",
"if",
"(",
"!",
"self",
"::",
"hasHandling",
"(",
")",
")",
"## there is no error",
"return",
"$",
"return",
";",
"$",
"stack",
"=",
"array_pop",
"(",
"self",
"::",
"$"... | Stopping The Error Handling Stack
!! It can using only for error not exceptions
@return null|ErrorException Last error if has | [
"Stopping",
"The",
"Error",
"Handling",
"Stack"
] | 67883b1b1dd2cea80fec3d98a199c403b8a23b4d | https://github.com/phPoirot/Std/blob/67883b1b1dd2cea80fec3d98a199c403b8a23b4d/src/ErrorStack.php#L190-L209 | train |
paulbunyannet/bandolier | src/Bandolier/Type/Paths.php | Paths.curlPath | public static function curlPath($toPath, $paths = null, $dockerEnv = "")
{
if (!$paths) {
$paths = new Paths();
}
if (!$dockerEnv) {
$dockerEnv = self::CURL_CHECK_FILE;
}
$serverName = self::serverName();
if ($paths->domainNameIsWeb($serverName)
|| ($paths->domainNameIsLocalHost($serverName) && $paths->checkForEnvironmentFile($dockerEnv))
) {
$serverName = $paths->getDomainNameWeb();
}
return self::httpProtocol() . '://' . $serverName . DIRECTORY_SEPARATOR . ltrim($toPath, DIRECTORY_SEPARATOR);
} | php | public static function curlPath($toPath, $paths = null, $dockerEnv = "")
{
if (!$paths) {
$paths = new Paths();
}
if (!$dockerEnv) {
$dockerEnv = self::CURL_CHECK_FILE;
}
$serverName = self::serverName();
if ($paths->domainNameIsWeb($serverName)
|| ($paths->domainNameIsLocalHost($serverName) && $paths->checkForEnvironmentFile($dockerEnv))
) {
$serverName = $paths->getDomainNameWeb();
}
return self::httpProtocol() . '://' . $serverName . DIRECTORY_SEPARATOR . ltrim($toPath, DIRECTORY_SEPARATOR);
} | [
"public",
"static",
"function",
"curlPath",
"(",
"$",
"toPath",
",",
"$",
"paths",
"=",
"null",
",",
"$",
"dockerEnv",
"=",
"\"\"",
")",
"{",
"if",
"(",
"!",
"$",
"paths",
")",
"{",
"$",
"paths",
"=",
"new",
"Paths",
"(",
")",
";",
"}",
"if",
"... | Check to see what curl path should be used. If running in
localhost or currently run inside a container use web,
otherwise use the current SERVER_NAME
@param string $toPath Path to start from
@param Paths $paths Instance of Path (or mock)
@param string $dockerEnv Path to environment file that should exist if we're in a docker container
@return string | [
"Check",
"to",
"see",
"what",
"curl",
"path",
"should",
"be",
"used",
".",
"If",
"running",
"in",
"localhost",
"or",
"currently",
"run",
"inside",
"a",
"container",
"use",
"web",
"otherwise",
"use",
"the",
"current",
"SERVER_NAME"
] | a98cb30bf63a18a7e3fc81418bf561ac36e9cd84 | https://github.com/paulbunyannet/bandolier/blob/a98cb30bf63a18a7e3fc81418bf561ac36e9cd84/src/Bandolier/Type/Paths.php#L74-L92 | train |
paulbunyannet/bandolier | src/Bandolier/Type/Paths.php | Paths.fileGetContents | public static function fileGetContents(array $params = [])
{
/** @var string $toPath Path to get request from */
/** @var array $clientParams parameters passed into client */
/** @var \GuzzleHttp\Client $client */
/** @var string $request_type request type */
/** @var array $requestParams parameters to pass into request */
/** @var string $request type of request */
$parameters = new Collection();
$parameters->addItems((array)Arrays::defaultAttributes([
"toPath" => self::httpProtocol() . '://' . self::serverName() . '/',
"clientParams" => [],
"client" => "\\GuzzleHttp\\Client",
"request" => "GET",
"requestParams" => [],
], $params));
$parameters->addItem(parse_url($parameters->getItem('toPath'), PHP_URL_SCHEME) . "://" . parse_url($parameters->getItem('toPath'), PHP_URL_HOST), 'base_uri');
$parameters->setItem(array_merge($parameters->getItem('clientParams'), array('base_uri' => $parameters->getItem('base_uri'))), 'clientParams');
if (is_string($parameters->getItem('client'))) {
$client = $parameters->getItem('client');
$parameters->setItem(new $client($parameters->getItem('clientParams')), 'client');
}
$path = substr($parameters->getItem('toPath'), strlen($parameters->getItem('base_uri')), strlen($parameters->getItem('toPath')));
if (method_exists($parameters->getItem('client'), 'request')) {
// For GuzzleHttp 6
return $parameters->getItem('client')
->request($parameters->getItem('request'), $path, $parameters->getItem('requestParams'))
->getBody()
->getContents();
} elseif (method_exists($parameters->getItem('client'), 'createRequest')) {
// for GuzzleHttp 5.3
$request = $parameters->getItem('client')
->createRequest($parameters->getItem('request'), $path, $parameters->getItem('requestParams'));
return $parameters->getItem('client')->send($request)->getBody();
} else {
throw new FileGetContentsException('The client must be an instance of \\GuzzleHttp\\Client');
}
} | php | public static function fileGetContents(array $params = [])
{
/** @var string $toPath Path to get request from */
/** @var array $clientParams parameters passed into client */
/** @var \GuzzleHttp\Client $client */
/** @var string $request_type request type */
/** @var array $requestParams parameters to pass into request */
/** @var string $request type of request */
$parameters = new Collection();
$parameters->addItems((array)Arrays::defaultAttributes([
"toPath" => self::httpProtocol() . '://' . self::serverName() . '/',
"clientParams" => [],
"client" => "\\GuzzleHttp\\Client",
"request" => "GET",
"requestParams" => [],
], $params));
$parameters->addItem(parse_url($parameters->getItem('toPath'), PHP_URL_SCHEME) . "://" . parse_url($parameters->getItem('toPath'), PHP_URL_HOST), 'base_uri');
$parameters->setItem(array_merge($parameters->getItem('clientParams'), array('base_uri' => $parameters->getItem('base_uri'))), 'clientParams');
if (is_string($parameters->getItem('client'))) {
$client = $parameters->getItem('client');
$parameters->setItem(new $client($parameters->getItem('clientParams')), 'client');
}
$path = substr($parameters->getItem('toPath'), strlen($parameters->getItem('base_uri')), strlen($parameters->getItem('toPath')));
if (method_exists($parameters->getItem('client'), 'request')) {
// For GuzzleHttp 6
return $parameters->getItem('client')
->request($parameters->getItem('request'), $path, $parameters->getItem('requestParams'))
->getBody()
->getContents();
} elseif (method_exists($parameters->getItem('client'), 'createRequest')) {
// for GuzzleHttp 5.3
$request = $parameters->getItem('client')
->createRequest($parameters->getItem('request'), $path, $parameters->getItem('requestParams'));
return $parameters->getItem('client')->send($request)->getBody();
} else {
throw new FileGetContentsException('The client must be an instance of \\GuzzleHttp\\Client');
}
} | [
"public",
"static",
"function",
"fileGetContents",
"(",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"/** @var string $toPath Path to get request from */",
"/** @var array $clientParams parameters passed into client */",
"/** @var \\GuzzleHttp\\Client $client */",
"/** @var strin... | Get content from a path
@param array $params parameters
@return string
@throws \Exception | [
"Get",
"content",
"from",
"a",
"path"
] | a98cb30bf63a18a7e3fc81418bf561ac36e9cd84 | https://github.com/paulbunyannet/bandolier/blob/a98cb30bf63a18a7e3fc81418bf561ac36e9cd84/src/Bandolier/Type/Paths.php#L166-L205 | train |
paulbunyannet/bandolier | src/Bandolier/Type/Paths.php | Paths.filePutContents | public static function filePutContents($filePath, $content = null)
{
// https://stackoverflow.com/a/282140/405758
if (!file_exists(dirname($filePath))) {
mkdir(dirname($filePath), 0775, true);
}
return file_put_contents($filePath, $content);
} | php | public static function filePutContents($filePath, $content = null)
{
// https://stackoverflow.com/a/282140/405758
if (!file_exists(dirname($filePath))) {
mkdir(dirname($filePath), 0775, true);
}
return file_put_contents($filePath, $content);
} | [
"public",
"static",
"function",
"filePutContents",
"(",
"$",
"filePath",
",",
"$",
"content",
"=",
"null",
")",
"{",
"// https://stackoverflow.com/a/282140/405758",
"if",
"(",
"!",
"file_exists",
"(",
"dirname",
"(",
"$",
"filePath",
")",
")",
")",
"{",
"mkdir... | Traverse path to make file
@param string $filePath path to file to check if it exists
@param string|null $content content of file to be written
@return bool|int | [
"Traverse",
"path",
"to",
"make",
"file"
] | a98cb30bf63a18a7e3fc81418bf561ac36e9cd84 | https://github.com/paulbunyannet/bandolier/blob/a98cb30bf63a18a7e3fc81418bf561ac36e9cd84/src/Bandolier/Type/Paths.php#L253-L260 | train |
froq/froq | src/App.php | App.configValue | public function configValue(string $key, $valueDefault = null)
{
return $this->config->get($key, $valueDefault);
} | php | public function configValue(string $key, $valueDefault = null)
{
return $this->config->get($key, $valueDefault);
} | [
"public",
"function",
"configValue",
"(",
"string",
"$",
"key",
",",
"$",
"valueDefault",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"$",
"key",
",",
"$",
"valueDefault",
")",
";",
"}"
] | Config value.
@param string $key
@param any $valueDefault
@return any | [
"Config",
"value",
"."
] | bc153ccec05585f66301cd632ff46bad91915029 | https://github.com/froq/froq/blob/bc153ccec05585f66301cd632ff46bad91915029/src/App.php#L243-L246 | train |
froq/froq | src/App.php | App.loadTime | public function loadTime(bool $totalStringOnly = true)
{
$start = APP_START_TIME; $end = microtime(true);
$total = $end - $start;
$totalString = sprintf('%.5f', $total);
if ($totalStringOnly) {
return $totalString;
}
return [$start, $end, $total, $totalString];
} | php | public function loadTime(bool $totalStringOnly = true)
{
$start = APP_START_TIME; $end = microtime(true);
$total = $end - $start;
$totalString = sprintf('%.5f', $total);
if ($totalStringOnly) {
return $totalString;
}
return [$start, $end, $total, $totalString];
} | [
"public",
"function",
"loadTime",
"(",
"bool",
"$",
"totalStringOnly",
"=",
"true",
")",
"{",
"$",
"start",
"=",
"APP_START_TIME",
";",
"$",
"end",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"total",
"=",
"$",
"end",
"-",
"$",
"start",
";",
"$",
... | Load time.
@param bool $totalStringOnly
@return array|string | [
"Load",
"time",
"."
] | bc153ccec05585f66301cd632ff46bad91915029 | https://github.com/froq/froq/blob/bc153ccec05585f66301cd632ff46bad91915029/src/App.php#L395-L406 | train |
froq/froq | src/App.php | App.setServiceMethod | public function setServiceMethod(string $method): void
{
$this->service && $this->service->setMethod($method);
} | php | public function setServiceMethod(string $method): void
{
$this->service && $this->service->setMethod($method);
} | [
"public",
"function",
"setServiceMethod",
"(",
"string",
"$",
"method",
")",
":",
"void",
"{",
"$",
"this",
"->",
"service",
"&&",
"$",
"this",
"->",
"service",
"->",
"setMethod",
"(",
"$",
"method",
")",
";",
"}"
] | Set service method.
@param string $method
@return void | [
"Set",
"service",
"method",
"."
] | bc153ccec05585f66301cd632ff46bad91915029 | https://github.com/froq/froq/blob/bc153ccec05585f66301cd632ff46bad91915029/src/App.php#L423-L426 | train |
froq/froq | src/App.php | App.applyConfig | private function applyConfig(array $config): void
{
// override
if ($this->config != null) {
$config = Config::merge($config, $this->config->getData());
}
$this->config = new Config($config);
// set/reset logger options
$loggerOptions = $this->config->get('logger');
if ($loggerOptions != null) {
isset($loggerOptions['level']) && $this->logger->setLevel($loggerOptions['level']);
isset($loggerOptions['directory']) && $this->logger->setDirectory($loggerOptions['directory']);
}
} | php | private function applyConfig(array $config): void
{
// override
if ($this->config != null) {
$config = Config::merge($config, $this->config->getData());
}
$this->config = new Config($config);
// set/reset logger options
$loggerOptions = $this->config->get('logger');
if ($loggerOptions != null) {
isset($loggerOptions['level']) && $this->logger->setLevel($loggerOptions['level']);
isset($loggerOptions['directory']) && $this->logger->setDirectory($loggerOptions['directory']);
}
} | [
"private",
"function",
"applyConfig",
"(",
"array",
"$",
"config",
")",
":",
"void",
"{",
"// override",
"if",
"(",
"$",
"this",
"->",
"config",
"!=",
"null",
")",
"{",
"$",
"config",
"=",
"Config",
"::",
"merge",
"(",
"$",
"config",
",",
"$",
"this"... | Apply config.
@param array $config
@return void | [
"Apply",
"config",
"."
] | bc153ccec05585f66301cd632ff46bad91915029 | https://github.com/froq/froq/blob/bc153ccec05585f66301cd632ff46bad91915029/src/App.php#L479-L493 | train |
froq/froq | src/App.php | App.applyDefaults | private function applyDefaults(): void
{
$timezone = $this->config->get('timezone');
if ($timezone != null) {
date_default_timezone_set($timezone);
}
$encoding = $this->config->get('encoding');
if ($encoding != null) {
mb_internal_encoding($encoding);
ini_set('default_charset', $encoding);
}
$locales = $this->config->get('locales');
if ($locales != null) {
foreach ((array) $locales as $category => $locale) {
setlocale($category, $locale);
}
}
} | php | private function applyDefaults(): void
{
$timezone = $this->config->get('timezone');
if ($timezone != null) {
date_default_timezone_set($timezone);
}
$encoding = $this->config->get('encoding');
if ($encoding != null) {
mb_internal_encoding($encoding);
ini_set('default_charset', $encoding);
}
$locales = $this->config->get('locales');
if ($locales != null) {
foreach ((array) $locales as $category => $locale) {
setlocale($category, $locale);
}
}
} | [
"private",
"function",
"applyDefaults",
"(",
")",
":",
"void",
"{",
"$",
"timezone",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'timezone'",
")",
";",
"if",
"(",
"$",
"timezone",
"!=",
"null",
")",
"{",
"date_default_timezone_set",
"(",
"$",
... | Apply defaults.
@return void | [
"Apply",
"defaults",
"."
] | bc153ccec05585f66301cd632ff46bad91915029 | https://github.com/froq/froq/blob/bc153ccec05585f66301cd632ff46bad91915029/src/App.php#L499-L518 | train |
froq/froq | src/App.php | App.endOutputBuffer | private function endOutputBuffer($output = null): void
{
// handle redirections
$statusCode = $this->response->status()->getCode();
if ($statusCode >= 300 && $statusCode <= 399) {
// clean & turn off output buffering
while (ob_get_level()) {
ob_end_clean();
}
$this->response->body()->setContentType('none');
}
// handle outputs
else {
// echo'd or print'ed service methods return 'null'
if ($output === null) {
$output = '';
while (ob_get_level()) {
$output .= ob_get_clean();
}
}
// call user output handler if provided
if ($this->events->has('app.output')) {
$output = $this->events->fire('app.output', $output);
}
$this->response->setBody($output);
}
$this->response->end();
} | php | private function endOutputBuffer($output = null): void
{
// handle redirections
$statusCode = $this->response->status()->getCode();
if ($statusCode >= 300 && $statusCode <= 399) {
// clean & turn off output buffering
while (ob_get_level()) {
ob_end_clean();
}
$this->response->body()->setContentType('none');
}
// handle outputs
else {
// echo'd or print'ed service methods return 'null'
if ($output === null) {
$output = '';
while (ob_get_level()) {
$output .= ob_get_clean();
}
}
// call user output handler if provided
if ($this->events->has('app.output')) {
$output = $this->events->fire('app.output', $output);
}
$this->response->setBody($output);
}
$this->response->end();
} | [
"private",
"function",
"endOutputBuffer",
"(",
"$",
"output",
"=",
"null",
")",
":",
"void",
"{",
"// handle redirections",
"$",
"statusCode",
"=",
"$",
"this",
"->",
"response",
"->",
"status",
"(",
")",
"->",
"getCode",
"(",
")",
";",
"if",
"(",
"$",
... | End output buffer.
@param any $output
@return void | [
"End",
"output",
"buffer",
"."
] | bc153ccec05585f66301cd632ff46bad91915029 | https://github.com/froq/froq/blob/bc153ccec05585f66301cd632ff46bad91915029/src/App.php#L536-L566 | train |
donatj/mddoc | src/Runner/ConfigParser.php | ConfigParser.parse | public function parse( $filename ) {
if( !is_readable($filename) ) {
throw new ConfigException("Config file '{$filename}' not readable");
}
$dom = new \DOMDocument();
if( @$dom->load($filename) === false ) {
throw new ConfigException("Error parsing {$filename}");
}
$root = $dom->firstChild;
if( !$root instanceof \DOMElement ) {
throw new \RuntimeException('Needs a DOM element');
}
$docRoot = new Documentation\DocRoot([], []);
if( $root->nodeName == 'mddoc' ) {
$this->loadChildren($root, $docRoot);
} else {
if( $root->nodeName ) {
throw new ConfigException("XML Root element `{$root->nodeName}` is invalid.");
}
throw new ConfigException("Error parsing {$filename}");
}
return $docRoot;
} | php | public function parse( $filename ) {
if( !is_readable($filename) ) {
throw new ConfigException("Config file '{$filename}' not readable");
}
$dom = new \DOMDocument();
if( @$dom->load($filename) === false ) {
throw new ConfigException("Error parsing {$filename}");
}
$root = $dom->firstChild;
if( !$root instanceof \DOMElement ) {
throw new \RuntimeException('Needs a DOM element');
}
$docRoot = new Documentation\DocRoot([], []);
if( $root->nodeName == 'mddoc' ) {
$this->loadChildren($root, $docRoot);
} else {
if( $root->nodeName ) {
throw new ConfigException("XML Root element `{$root->nodeName}` is invalid.");
}
throw new ConfigException("Error parsing {$filename}");
}
return $docRoot;
} | [
"public",
"function",
"parse",
"(",
"$",
"filename",
")",
"{",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"filename",
")",
")",
"{",
"throw",
"new",
"ConfigException",
"(",
"\"Config file '{$filename}' not readable\"",
")",
";",
"}",
"$",
"dom",
"=",
"new",
... | Parse a config file
@param string $filename
@return \donatj\MDDoc\Documentation\DocRoot
@throws \donatj\MDDoc\Exceptions\ConfigException | [
"Parse",
"a",
"config",
"file"
] | 3db2c0980dc54dbc46748fe8650242ead344ba82 | https://github.com/donatj/mddoc/blob/3db2c0980dc54dbc46748fe8650242ead344ba82/src/Runner/ConfigParser.php#L140-L167 | train |
phPoirot/Std | src/Type/StdTravers.php | StdTravers.toArray | function toArray(\Closure $filter = null, $recursive = false)
{
$arr = array();
foreach($this->getIterator() as $key => $val)
{
if ($recursive && ( $val instanceof \Traversable || is_array($val) ) ) {
// (A) At the end value can be empty by filter
## deep convert
$val = StdTravers::of($val)->toArray($filter, $recursive);
}
// (B) So Filter Check Placed After Recursive Calls
$flag = false;
if ($filter !== null)
$flag = $filter($val, $key);
if ($flag) continue;
if (! \Poirot\Std\isStringify($key) )
## some poirot Traversable is able to handle objects as key
$key = \Poirot\Std\flatten($key);
$arr[(string) $key] = $val;
}
return $arr;
} | php | function toArray(\Closure $filter = null, $recursive = false)
{
$arr = array();
foreach($this->getIterator() as $key => $val)
{
if ($recursive && ( $val instanceof \Traversable || is_array($val) ) ) {
// (A) At the end value can be empty by filter
## deep convert
$val = StdTravers::of($val)->toArray($filter, $recursive);
}
// (B) So Filter Check Placed After Recursive Calls
$flag = false;
if ($filter !== null)
$flag = $filter($val, $key);
if ($flag) continue;
if (! \Poirot\Std\isStringify($key) )
## some poirot Traversable is able to handle objects as key
$key = \Poirot\Std\flatten($key);
$arr[(string) $key] = $val;
}
return $arr;
} | [
"function",
"toArray",
"(",
"\\",
"Closure",
"$",
"filter",
"=",
"null",
",",
"$",
"recursive",
"=",
"false",
")",
"{",
"$",
"arr",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getIterator",
"(",
")",
"as",
"$",
"key",
"=>",
"... | Convert Iterator To An Array
filter:
// return true mean not present to output array
bool function(&$val, &$key = null);
@param \Closure|null $filter
@param bool $recursive Recursively convert values that can be iterated
@return array | [
"Convert",
"Iterator",
"To",
"An",
"Array"
] | 67883b1b1dd2cea80fec3d98a199c403b8a23b4d | https://github.com/phPoirot/Std/blob/67883b1b1dd2cea80fec3d98a199c403b8a23b4d/src/Type/StdTravers.php#L70-L97 | train |
phPoirot/Std | src/Type/StdTravers.php | StdTravers.chain | function chain(\Closure $func, $default = null)
{
$i = 0;
$prev = $default;
foreach ($this->getIterator() as $key => $val) {
if ($i++ !== 0)
$prev = $func($val, $key, $prev);
else
// use default value of argument of given closure
$prev = $func($val, $key);
}
return $prev;
} | php | function chain(\Closure $func, $default = null)
{
$i = 0;
$prev = $default;
foreach ($this->getIterator() as $key => $val) {
if ($i++ !== 0)
$prev = $func($val, $key, $prev);
else
// use default value of argument of given closure
$prev = $func($val, $key);
}
return $prev;
} | [
"function",
"chain",
"(",
"\\",
"Closure",
"$",
"func",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"i",
"=",
"0",
";",
"$",
"prev",
"=",
"$",
"default",
";",
"foreach",
"(",
"$",
"this",
"->",
"getIterator",
"(",
")",
"as",
"$",
"key",
"=... | With Each Item
$prev is previous value that func return
@param \Closure $func fun($val, $key, $prev)
@return mixed | [
"With",
"Each",
"Item"
] | 67883b1b1dd2cea80fec3d98a199c403b8a23b4d | https://github.com/phPoirot/Std/blob/67883b1b1dd2cea80fec3d98a199c403b8a23b4d/src/Type/StdTravers.php#L107-L121 | train |
paulbunyannet/bandolier | src/Bandolier/Type/Strings.php | Strings.titleCase | public static function titleCase(
$value,
$delimiters = [" ", "-", ".", "'", "O'", "Mc"],
$exceptions = ["and", "to", "of", "das", "dos", "I", "II", "III", "IV", "V", "VI"]
) {
// if value passed as empty or is not a string then return false
if (!$value) {
return false;
}
/** @var string $cache Cache Value */
$cache = self::cacheString($value, $delimiters, $exceptions);
// check for cache
if (isset(static::$titleCaseCache[$cache])) {
return static::$titleCaseCache[$cache];
}
/*
* Exceptions in lower case are words you don't want converted
* Exceptions all in upper case are any words you don't want converted to title case
* but should be converted to upper case, e.g.:
* king henry viii or king henry Viii should be King Henry VIII
*/
$value = mb_convert_case($value, MB_CASE_TITLE, "UTF-8");
foreach ($delimiters as $delimiter) {
$words = explode($delimiter, $value);
$newWords = [];
foreach ($words as $word) {
if (in_array(mb_strtoupper($word, "UTF-8"), $exceptions)) {
// check exceptions list for any words that should be in upper case
$word = mb_strtoupper($word, "UTF-8");
} elseif (in_array(mb_strtolower($word, "UTF-8"), $exceptions)) {
// check exceptions list for any words that should be in upper case
$word = mb_strtolower($word, "UTF-8");
} elseif (!in_array($word, $exceptions)) {
// convert to uppercase (non-utf8 only)
$word = ucfirst($word);
}
array_push($newWords, $word);
}
$value = join($delimiter, $newWords);
}
return static::$formatForTitleCache[$cache] = $value;
} | php | public static function titleCase(
$value,
$delimiters = [" ", "-", ".", "'", "O'", "Mc"],
$exceptions = ["and", "to", "of", "das", "dos", "I", "II", "III", "IV", "V", "VI"]
) {
// if value passed as empty or is not a string then return false
if (!$value) {
return false;
}
/** @var string $cache Cache Value */
$cache = self::cacheString($value, $delimiters, $exceptions);
// check for cache
if (isset(static::$titleCaseCache[$cache])) {
return static::$titleCaseCache[$cache];
}
/*
* Exceptions in lower case are words you don't want converted
* Exceptions all in upper case are any words you don't want converted to title case
* but should be converted to upper case, e.g.:
* king henry viii or king henry Viii should be King Henry VIII
*/
$value = mb_convert_case($value, MB_CASE_TITLE, "UTF-8");
foreach ($delimiters as $delimiter) {
$words = explode($delimiter, $value);
$newWords = [];
foreach ($words as $word) {
if (in_array(mb_strtoupper($word, "UTF-8"), $exceptions)) {
// check exceptions list for any words that should be in upper case
$word = mb_strtoupper($word, "UTF-8");
} elseif (in_array(mb_strtolower($word, "UTF-8"), $exceptions)) {
// check exceptions list for any words that should be in upper case
$word = mb_strtolower($word, "UTF-8");
} elseif (!in_array($word, $exceptions)) {
// convert to uppercase (non-utf8 only)
$word = ucfirst($word);
}
array_push($newWords, $word);
}
$value = join($delimiter, $newWords);
}
return static::$formatForTitleCache[$cache] = $value;
} | [
"public",
"static",
"function",
"titleCase",
"(",
"$",
"value",
",",
"$",
"delimiters",
"=",
"[",
"\" \"",
",",
"\"-\"",
",",
"\".\"",
",",
"\"'\"",
",",
"\"O'\"",
",",
"\"Mc\"",
"]",
",",
"$",
"exceptions",
"=",
"[",
"\"and\"",
",",
"\"to\"",
",",
"... | Convert a string to Title Case
@param string $value String to convert
@param array $delimiters Delimiters to break into apart words
@param array $exceptions strings to skip when capitalizing
@return string|bool | [
"Convert",
"a",
"string",
"to",
"Title",
"Case"
] | a98cb30bf63a18a7e3fc81418bf561ac36e9cd84 | https://github.com/paulbunyannet/bandolier/blob/a98cb30bf63a18a7e3fc81418bf561ac36e9cd84/src/Bandolier/Type/Strings.php#L217-L261 | train |
paulbunyannet/bandolier | src/Bandolier/Type/Strings.php | Strings.stripOuterQuotes | public static function stripOuterQuotes($value = "")
{
// if value passed as empty or is not a string then return false
if (!$value) {
return false;
}
/** @var string $cache Cache Value */
$cache = self::cacheString($value);
// check for cache
if (isset(static::$stripOuterQuotesCache[$cache])) {
return static::$stripOuterQuotesCache[$cache];
}
$start = (strlen($value) > 1 && self::startsWith($value, '"'))
|| (strlen($value) > 1 && self::startsWith($value, '\''));
$end = (strlen($value) > 1 && self::endsWith($value, '"'))
|| (strlen($value) > 1 && self::endsWith($value, '\''));
if ($start && $end) {
return static::$stripOuterQuotesCache[$cache] = substr($value, 1, -1);
}
return static::$stripOuterQuotesCache[$cache] = $value;
} | php | public static function stripOuterQuotes($value = "")
{
// if value passed as empty or is not a string then return false
if (!$value) {
return false;
}
/** @var string $cache Cache Value */
$cache = self::cacheString($value);
// check for cache
if (isset(static::$stripOuterQuotesCache[$cache])) {
return static::$stripOuterQuotesCache[$cache];
}
$start = (strlen($value) > 1 && self::startsWith($value, '"'))
|| (strlen($value) > 1 && self::startsWith($value, '\''));
$end = (strlen($value) > 1 && self::endsWith($value, '"'))
|| (strlen($value) > 1 && self::endsWith($value, '\''));
if ($start && $end) {
return static::$stripOuterQuotesCache[$cache] = substr($value, 1, -1);
}
return static::$stripOuterQuotesCache[$cache] = $value;
} | [
"public",
"static",
"function",
"stripOuterQuotes",
"(",
"$",
"value",
"=",
"\"\"",
")",
"{",
"// if value passed as empty or is not a string then return false",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"return",
"false",
";",
"}",
"/** @var string $cache Cache Value */"... | Strip outer quotes from a string
@param string $value
@return bool|string
@throws \Exception | [
"Strip",
"outer",
"quotes",
"from",
"a",
"string"
] | a98cb30bf63a18a7e3fc81418bf561ac36e9cd84 | https://github.com/paulbunyannet/bandolier/blob/a98cb30bf63a18a7e3fc81418bf561ac36e9cd84/src/Bandolier/Type/Strings.php#L328-L353 | train |
paulbunyannet/bandolier | src/Bandolier/Type/Strings.php | Strings.cacheString | protected static function cacheString()
{
$string = "";
foreach (func_get_args() as $functionArgument) {
$string .= md5(serialize($functionArgument));
}
return $string;
} | php | protected static function cacheString()
{
$string = "";
foreach (func_get_args() as $functionArgument) {
$string .= md5(serialize($functionArgument));
}
return $string;
} | [
"protected",
"static",
"function",
"cacheString",
"(",
")",
"{",
"$",
"string",
"=",
"\"\"",
";",
"foreach",
"(",
"func_get_args",
"(",
")",
"as",
"$",
"functionArgument",
")",
"{",
"$",
"string",
".=",
"md5",
"(",
"serialize",
"(",
"$",
"functionArgument"... | Create a cache string from function attributes
@return null|string | [
"Create",
"a",
"cache",
"string",
"from",
"function",
"attributes"
] | a98cb30bf63a18a7e3fc81418bf561ac36e9cd84 | https://github.com/paulbunyannet/bandolier/blob/a98cb30bf63a18a7e3fc81418bf561ac36e9cd84/src/Bandolier/Type/Strings.php#L433-L441 | train |
mcaskill/charcoal-support | src/Email/ManufacturableEmailTrait.php | ManufacturableEmailTrait.emailFactory | protected function emailFactory()
{
if (!isset($this->emailFactory)) {
throw new RuntimeException(sprintf(
'Email Factory is not defined for [%s]',
get_class($this)
));
}
return $this->emailFactory;
} | php | protected function emailFactory()
{
if (!isset($this->emailFactory)) {
throw new RuntimeException(sprintf(
'Email Factory is not defined for [%s]',
get_class($this)
));
}
return $this->emailFactory;
} | [
"protected",
"function",
"emailFactory",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"emailFactory",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Email Factory is not defined for [%s]'",
",",
"get_class",
"(",
"... | Retrieve the email model factory.
@throws RuntimeException If the model factory is missing.
@return FactoryInterface | [
"Retrieve",
"the",
"email",
"model",
"factory",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Email/ManufacturableEmailTrait.php#L39-L49 | train |
phPoirot/Std | src/Struct/fixes/DataEntity.php | DataEntity.del | function del($key)
{
if ($key !== $hash = $this->_normalizeKey($key))
$key = $hash;
$properties = &$this->_referDataArrayReference();
if (array_key_exists($key, $properties)) {
unset($properties[$key]);
unset($this->__mapedPropObjects[$hash]);
}
return $this;
} | php | function del($key)
{
if ($key !== $hash = $this->_normalizeKey($key))
$key = $hash;
$properties = &$this->_referDataArrayReference();
if (array_key_exists($key, $properties)) {
unset($properties[$key]);
unset($this->__mapedPropObjects[$hash]);
}
return $this;
} | [
"function",
"del",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"key",
"!==",
"$",
"hash",
"=",
"$",
"this",
"->",
"_normalizeKey",
"(",
"$",
"key",
")",
")",
"$",
"key",
"=",
"$",
"hash",
";",
"$",
"properties",
"=",
"&",
"$",
"this",
"->",
"_... | Delete a property
@param string $key Property
@return $this | [
"Delete",
"a",
"property"
] | 67883b1b1dd2cea80fec3d98a199c403b8a23b4d | https://github.com/phPoirot/Std/blob/67883b1b1dd2cea80fec3d98a199c403b8a23b4d/src/Struct/fixes/DataEntity.php#L121-L134 | train |
phPoirot/Std | src/Struct/fixes/DataEntity.php | DataEntity._normalizeKey | protected function _normalizeKey($key)
{
if (!is_string($key) && !is_numeric($key))
$key = md5(Std\flatten($key));
return $key;
} | php | protected function _normalizeKey($key)
{
if (!is_string($key) && !is_numeric($key))
$key = md5(Std\flatten($key));
return $key;
} | [
"protected",
"function",
"_normalizeKey",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"key",
")",
")",
"$",
"key",
"=",
"md5",
"(",
"Std",
"\\",
"flatten",
"(",
"$",
"key",
")",... | Make hash string for none scalars
@param string|mixed $key
@return string | [
"Make",
"hash",
"string",
"for",
"none",
"scalars"
] | 67883b1b1dd2cea80fec3d98a199c403b8a23b4d | https://github.com/phPoirot/Std/blob/67883b1b1dd2cea80fec3d98a199c403b8a23b4d/src/Struct/fixes/DataEntity.php#L144-L150 | train |
apioo/psx-http | src/Stream/FileStream.php | FileStream.move | public function move($toFile)
{
if ($this->error == UPLOAD_ERR_OK) {
return move_uploaded_file($this->tmpName, $toFile);
} else {
return false;
}
} | php | public function move($toFile)
{
if ($this->error == UPLOAD_ERR_OK) {
return move_uploaded_file($this->tmpName, $toFile);
} else {
return false;
}
} | [
"public",
"function",
"move",
"(",
"$",
"toFile",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"error",
"==",
"UPLOAD_ERR_OK",
")",
"{",
"return",
"move_uploaded_file",
"(",
"$",
"this",
"->",
"tmpName",
",",
"$",
"toFile",
")",
";",
"}",
"else",
"{",
"re... | Moves the uploaded file to a new location
@param string $toFile
@return boolean | [
"Moves",
"the",
"uploaded",
"file",
"to",
"a",
"new",
"location"
] | c54d7212cfb513df84f810429aa34c6ac9942c01 | https://github.com/apioo/psx-http/blob/c54d7212cfb513df84f810429aa34c6ac9942c01/src/Stream/FileStream.php#L125-L132 | train |
nails/module-email | src/Factory/Email.php | Email.addRecipient | protected function addRecipient($mUserIdOrEmail, $bAppend, &$aArray)
{
if (!$bAppend) {
$aArray = [];
}
if (strpos($mUserIdOrEmail, ',') !== false) {
$mUserIdOrEmail = array_map('trim', explode(',', $mUserIdOrEmail));
}
if (is_array($mUserIdOrEmail)) {
foreach ($mUserIdOrEmail as $sUserIdOrEmail) {
$this->addRecipient($sUserIdOrEmail, true, $aArray);
}
} else {
$this->validateEmail($mUserIdOrEmail);
$aArray[] = $mUserIdOrEmail;
}
return $this;
} | php | protected function addRecipient($mUserIdOrEmail, $bAppend, &$aArray)
{
if (!$bAppend) {
$aArray = [];
}
if (strpos($mUserIdOrEmail, ',') !== false) {
$mUserIdOrEmail = array_map('trim', explode(',', $mUserIdOrEmail));
}
if (is_array($mUserIdOrEmail)) {
foreach ($mUserIdOrEmail as $sUserIdOrEmail) {
$this->addRecipient($sUserIdOrEmail, true, $aArray);
}
} else {
$this->validateEmail($mUserIdOrEmail);
$aArray[] = $mUserIdOrEmail;
}
return $this;
} | [
"protected",
"function",
"addRecipient",
"(",
"$",
"mUserIdOrEmail",
",",
"$",
"bAppend",
",",
"&",
"$",
"aArray",
")",
"{",
"if",
"(",
"!",
"$",
"bAppend",
")",
"{",
"$",
"aArray",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"mUserIdOr... | Adds a recipient
@param integer|string $mUserIdOrEmail The user ID to send to, or an email address
@param bool $bAppend Whether to add to the list of recipients or not
@param array $aArray The array to add the recipient to
@return $this | [
"Adds",
"a",
"recipient"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Factory/Email.php#L164-L184 | train |
nails/module-email | src/Factory/Email.php | Email.data | public function data($mKey, $mValue = null)
{
if (is_array($mKey)) {
foreach ($mKey as $sKey => $mValue) {
$this->data($sKey, $mValue);
}
} else {
$this->aData[$mKey] = $mValue;
}
return $this;
} | php | public function data($mKey, $mValue = null)
{
if (is_array($mKey)) {
foreach ($mKey as $sKey => $mValue) {
$this->data($sKey, $mValue);
}
} else {
$this->aData[$mKey] = $mValue;
}
return $this;
} | [
"public",
"function",
"data",
"(",
"$",
"mKey",
",",
"$",
"mValue",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"mKey",
")",
")",
"{",
"foreach",
"(",
"$",
"mKey",
"as",
"$",
"sKey",
"=>",
"$",
"mValue",
")",
"{",
"$",
"this",
"->",... | Set email payload data
@param array|string $mKey An array of key value pairs, or the key if supplying the second parameter
@param mixed $mValue The value
@return $this | [
"Set",
"email",
"payload",
"data"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Factory/Email.php#L232-L243 | train |
phPoirot/Std | src/Type/fixes/StdArray.php | StdArray.& | function &select($query)
{
/**
* @param $query
* @param $stackArr
* @return array|null
*/
$_f__select = function & ($query, &$stackArr) use (&$_f__select)
{
$queryOrig = $query;
if (strpos($query, '/') === 0)
## ignore first slash from instructions
## it cause an empty unwanted item on command stacks(exploded instructions)
## (withespace instruction has meaningful command "//item_on_any_depth")
$query = substr($query, 1);
if (!is_array($stackArr) && $query !== '') {
// notice: only variable by reference must return
$z = null;
return $x = &$z;
}
if ($query === '')
return $stackArr;
$instructions = explode('/', $query);
$ins = array_shift($instructions);
$remainQuery = implode('/', $instructions);
## match find(//):
if ($ins === '') {
### looking for any array elements to match query
$return = array();
foreach($stackArr as &$v) {
$r = &$_f__select($remainQuery, $v);
if ($r !== null)
$return[] = &$r;
if (is_array($v)) {
#### continue with deeper data
$r = &$_f__select($queryOrig, $v);
if ($r !== null) {
$return = array_merge($return, $r);
}
}
}
if (empty($return)) {
// notice: only variable by reference must return
$z = null;
return @$x = &$z;
}
return $return;
}
## match wildcard:
if ($ins === '*') {
$return = array();
foreach($stackArr as &$v)
$return[] = &$_f__select($remainQuery, $v);
return $return;
}
## match data item against current query instruct:
if (array_key_exists($ins, $stackArr))
### looking for exact match of an item:
### /*/[query/to/match/item]
return $_f__select($remainQuery, $stackArr[$ins]);
else {
## nothing match query
// notice: only variable by reference must return
$z = null;
return $x = &$z;
}
};
return $_f__select($query, $this->value);
} | php | function &select($query)
{
/**
* @param $query
* @param $stackArr
* @return array|null
*/
$_f__select = function & ($query, &$stackArr) use (&$_f__select)
{
$queryOrig = $query;
if (strpos($query, '/') === 0)
## ignore first slash from instructions
## it cause an empty unwanted item on command stacks(exploded instructions)
## (withespace instruction has meaningful command "//item_on_any_depth")
$query = substr($query, 1);
if (!is_array($stackArr) && $query !== '') {
// notice: only variable by reference must return
$z = null;
return $x = &$z;
}
if ($query === '')
return $stackArr;
$instructions = explode('/', $query);
$ins = array_shift($instructions);
$remainQuery = implode('/', $instructions);
## match find(//):
if ($ins === '') {
### looking for any array elements to match query
$return = array();
foreach($stackArr as &$v) {
$r = &$_f__select($remainQuery, $v);
if ($r !== null)
$return[] = &$r;
if (is_array($v)) {
#### continue with deeper data
$r = &$_f__select($queryOrig, $v);
if ($r !== null) {
$return = array_merge($return, $r);
}
}
}
if (empty($return)) {
// notice: only variable by reference must return
$z = null;
return @$x = &$z;
}
return $return;
}
## match wildcard:
if ($ins === '*') {
$return = array();
foreach($stackArr as &$v)
$return[] = &$_f__select($remainQuery, $v);
return $return;
}
## match data item against current query instruct:
if (array_key_exists($ins, $stackArr))
### looking for exact match of an item:
### /*/[query/to/match/item]
return $_f__select($remainQuery, $stackArr[$ins]);
else {
## nothing match query
// notice: only variable by reference must return
$z = null;
return $x = &$z;
}
};
return $_f__select($query, $this->value);
} | [
"function",
"&",
"select",
"(",
"$",
"query",
")",
"{",
"/**\n * @param $query\n * @param $stackArr\n * @return array|null\n */",
"$",
"_f__select",
"=",
"function",
"&",
"(",
"$",
"query",
",",
"&",
"$",
"stackArr",
")",
"use",
"(",
"&... | Select Bunch Of Items Regard To Given Query
!! for reference return must call with reference
&$stdArr->select('/1/Passenger/Credentials');
$result->select('/* /Passengers');
mean from root-any key presentation - that contains Passenger
$result->select('/insurance|hotels/Passengers');
mean from root-insurance|hotels-that contains Passenger
@param string $query
@return &mixed | [
"Select",
"Bunch",
"Of",
"Items",
"Regard",
"To",
"Given",
"Query"
] | 67883b1b1dd2cea80fec3d98a199c403b8a23b4d | https://github.com/phPoirot/Std/blob/67883b1b1dd2cea80fec3d98a199c403b8a23b4d/src/Type/fixes/StdArray.php#L97-L177 | train |
phpgithook/hello-world | src/Hooks/PrepareCommitMsg.php | PrepareCommitMsg.prepareCommitMsg | public function prepareCommitMsg(
string &$message,
InputInterface $input,
OutputInterface $output,
ParameterBagInterface $configuration,
?string $type = null,
?string $sha = null
): bool {
// Lets add some sweet text to the commit message
$message = 'sweet text '.$message;
// And return true, because the message is good
return true;
} | php | public function prepareCommitMsg(
string &$message,
InputInterface $input,
OutputInterface $output,
ParameterBagInterface $configuration,
?string $type = null,
?string $sha = null
): bool {
// Lets add some sweet text to the commit message
$message = 'sweet text '.$message;
// And return true, because the message is good
return true;
} | [
"public",
"function",
"prepareCommitMsg",
"(",
"string",
"&",
"$",
"message",
",",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
",",
"ParameterBagInterface",
"$",
"configuration",
",",
"?",
"string",
"$",
"type",
"=",
"null",
",",
"?"... | Called after receiving the default commit message, just prior to firing up the commit message editor.
Returning false aborts the commit.
This is used to edit the message in a way that cannot be suppressed.
@param string $message Commit message
@param InputInterface $input
@param OutputInterface $output
@param ParameterBagInterface $configuration
@param string|null $type Type of commit message (message, template, merge, squash, or commit)
@param string|null $sha SHA-1 of the commit (only available if working on a existing commit)
@return bool | [
"Called",
"after",
"receiving",
"the",
"default",
"commit",
"message",
"just",
"prior",
"to",
"firing",
"up",
"the",
"commit",
"message",
"editor",
"."
] | c01e5d57b24f5b4823c4007127d8fdf401f2f7da | https://github.com/phpgithook/hello-world/blob/c01e5d57b24f5b4823c4007127d8fdf401f2f7da/src/Hooks/PrepareCommitMsg.php#L28-L41 | train |
rodrigoiii/skeleton-core | src/classes/Console/Commands/MakeTransformerCommand.php | MakeTransformerCommand.makeTemplate | private function makeTemplate($transformer, $model, $template)
{
$template = !empty($template) ? "-{$template}" : "";
$file = __DIR__ . "/../templates/transformer/transformer{$template}.php.dist";
if (file_exists($file))
{
$template = strtr(file_get_contents($file), [
'{{namespace}}' => get_app_namespace(),
'{{transformer}}' => $transformer,
'{{model}}' => $model,
'{{model_small}}' => strtolower($model),
]);
if (!file_exists(app_path("Transformers")))
{
mkdir(app_path("Transformers"), 0755, true);
}
$file_path = app_path("Transformers/{$transformer}.php");
$file = fopen($file_path, "w");
fwrite($file, $template);
fclose($file);
return file_exists($file_path);
}
return false;
} | php | private function makeTemplate($transformer, $model, $template)
{
$template = !empty($template) ? "-{$template}" : "";
$file = __DIR__ . "/../templates/transformer/transformer{$template}.php.dist";
if (file_exists($file))
{
$template = strtr(file_get_contents($file), [
'{{namespace}}' => get_app_namespace(),
'{{transformer}}' => $transformer,
'{{model}}' => $model,
'{{model_small}}' => strtolower($model),
]);
if (!file_exists(app_path("Transformers")))
{
mkdir(app_path("Transformers"), 0755, true);
}
$file_path = app_path("Transformers/{$transformer}.php");
$file = fopen($file_path, "w");
fwrite($file, $template);
fclose($file);
return file_exists($file_path);
}
return false;
} | [
"private",
"function",
"makeTemplate",
"(",
"$",
"transformer",
",",
"$",
"model",
",",
"$",
"template",
")",
"{",
"$",
"template",
"=",
"!",
"empty",
"(",
"$",
"template",
")",
"?",
"\"-{$template}\"",
":",
"\"\"",
";",
"$",
"file",
"=",
"__DIR__",
".... | Create the transformer template.
@depends handle
@param string $transformer
@param string $model
@param boolean $template
@return boolean | [
"Create",
"the",
"transformer",
"template",
"."
] | 5dab0637b9cd0f55a64b1f5926d7ba6bb3f93df0 | https://github.com/rodrigoiii/skeleton-core/blob/5dab0637b9cd0f55a64b1f5926d7ba6bb3f93df0/src/classes/Console/Commands/MakeTransformerCommand.php#L72-L101 | train |
cmsgears/module-core | common/models/resources/Stats.php | Stats.getRowCount | public static function getRowCount( $table, $type = 'row' ) {
$stat = self::find()->where( '`table`=:table AND type=:type', [ ':table' => $table, ':type' => $type ] )->one();
if( isset( $stat ) ) {
return $stat->count;
}
return 0;
} | php | public static function getRowCount( $table, $type = 'row' ) {
$stat = self::find()->where( '`table`=:table AND type=:type', [ ':table' => $table, ':type' => $type ] )->one();
if( isset( $stat ) ) {
return $stat->count;
}
return 0;
} | [
"public",
"static",
"function",
"getRowCount",
"(",
"$",
"table",
",",
"$",
"type",
"=",
"'row'",
")",
"{",
"$",
"stat",
"=",
"self",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"'`table`=:table AND type=:type'",
",",
"[",
"':table'",
"=>",
"$",
"table",... | Returns row count for given table and type.
@param string $table
@param string $type
@return integer | [
"Returns",
"row",
"count",
"for",
"given",
"table",
"and",
"type",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/Stats.php#L135-L145 | train |
cmsgears/module-core | common/utilities/DataUtil.php | DataUtil.sortObjectArrayByNumber | public static function sortObjectArrayByNumber( $array, $attribute, $asc = true ) {
uasort( $array, function( $item1, $item2 ) use ( $attribute, $asc ) {
if( $asc ) {
return $item1->$attribute > $item2->$attribute;
}
else {
return $item1->$attribute < $item2->$attribute;
}
});
return $array;
} | php | public static function sortObjectArrayByNumber( $array, $attribute, $asc = true ) {
uasort( $array, function( $item1, $item2 ) use ( $attribute, $asc ) {
if( $asc ) {
return $item1->$attribute > $item2->$attribute;
}
else {
return $item1->$attribute < $item2->$attribute;
}
});
return $array;
} | [
"public",
"static",
"function",
"sortObjectArrayByNumber",
"(",
"$",
"array",
",",
"$",
"attribute",
",",
"$",
"asc",
"=",
"true",
")",
"{",
"uasort",
"(",
"$",
"array",
",",
"function",
"(",
"$",
"item1",
",",
"$",
"item2",
")",
"use",
"(",
"$",
"at... | The method sort give object array using the attribute having number value. The array objects will be sorted in ascending order by default.
It expects that all the array elements must have the given attribute. | [
"The",
"method",
"sort",
"give",
"object",
"array",
"using",
"the",
"attribute",
"having",
"number",
"value",
".",
"The",
"array",
"objects",
"will",
"be",
"sorted",
"in",
"ascending",
"order",
"by",
"default",
".",
"It",
"expects",
"that",
"all",
"the",
"... | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/utilities/DataUtil.php#L32-L47 | train |
nails/module-email | email/controllers/Verify.php | Verify.index | public function index()
{
$oUri = Factory::service('Uri');
$oInput = Factory::service('Input');
$oSession = Factory::service('Session', 'nails/module-auth');
$oUserModel = Factory::model('User', 'nails/module-auth');
$iId = $oUri->segment(3);
$sCode = $oUri->segment(4);
$sStatus = '';
$sMessage = '';
$oUser = $oUserModel->getById($iId);
if ($oUser && !$oUser->email_is_verified && $sCode) {
try {
if (!$oUserModel->emailVerify($oUser->id, $sCode)) {
throw new NailsException($oUserModel->lastError());
}
// Reward referrer (if any)
if (!empty($oUser->referred_by)) {
$oUserModel->rewardReferral($oUser->id, $oUser->referred_by);
}
$sStatus = 'success';
$sMessage = 'Success! Email verified successfully, thanks!';
} catch (\Exception $e) {
$sStatus = 'error';
$sMessage = 'Sorry, we couldn\'t verify your email address. ' . $e->getMessage();
}
}
// --------------------------------------------------------------------------
if ($oInput->get('return_to')) {
$sRedirect = $oInput->get('return_to');
} elseif (!isLoggedIn() && $oUser) {
if ($oUser->temp_pw) {
$sRedirect = 'auth/password/reset/' . $oUser->id . '/' . md5($oUser->salt);
} else {
$oUserModel->setLoginData($oUser->id);
$sRedirect = $oUser->group_homepage;
}
} elseif ($oUser) {
$sRedirect = $oUser->group_homepage;
} else {
$sRedirect = '/';
}
if (!empty($sStatus)) {
$oSession->setFlashData(
$sStatus,
$sMessage
);
}
redirect($sRedirect);
} | php | public function index()
{
$oUri = Factory::service('Uri');
$oInput = Factory::service('Input');
$oSession = Factory::service('Session', 'nails/module-auth');
$oUserModel = Factory::model('User', 'nails/module-auth');
$iId = $oUri->segment(3);
$sCode = $oUri->segment(4);
$sStatus = '';
$sMessage = '';
$oUser = $oUserModel->getById($iId);
if ($oUser && !$oUser->email_is_verified && $sCode) {
try {
if (!$oUserModel->emailVerify($oUser->id, $sCode)) {
throw new NailsException($oUserModel->lastError());
}
// Reward referrer (if any)
if (!empty($oUser->referred_by)) {
$oUserModel->rewardReferral($oUser->id, $oUser->referred_by);
}
$sStatus = 'success';
$sMessage = 'Success! Email verified successfully, thanks!';
} catch (\Exception $e) {
$sStatus = 'error';
$sMessage = 'Sorry, we couldn\'t verify your email address. ' . $e->getMessage();
}
}
// --------------------------------------------------------------------------
if ($oInput->get('return_to')) {
$sRedirect = $oInput->get('return_to');
} elseif (!isLoggedIn() && $oUser) {
if ($oUser->temp_pw) {
$sRedirect = 'auth/password/reset/' . $oUser->id . '/' . md5($oUser->salt);
} else {
$oUserModel->setLoginData($oUser->id);
$sRedirect = $oUser->group_homepage;
}
} elseif ($oUser) {
$sRedirect = $oUser->group_homepage;
} else {
$sRedirect = '/';
}
if (!empty($sStatus)) {
$oSession->setFlashData(
$sStatus,
$sMessage
);
}
redirect($sRedirect);
} | [
"public",
"function",
"index",
"(",
")",
"{",
"$",
"oUri",
"=",
"Factory",
"::",
"service",
"(",
"'Uri'",
")",
";",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"$",
"oSession",
"=",
"Factory",
"::",
"service",
"(",
"'Ses... | Attempt to validate the user's activation code | [
"Attempt",
"to",
"validate",
"the",
"user",
"s",
"activation",
"code"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/email/controllers/Verify.php#L22-L81 | train |
apioo/psx-http | src/Response.php | Response.setStatus | public function setStatus($code, $reasonPhrase = null)
{
$this->code = (int) $code;
if ($reasonPhrase !== null) {
$this->reasonPhrase = $reasonPhrase;
} elseif (isset(Http::$codes[$this->code])) {
$this->reasonPhrase = Http::$codes[$this->code];
}
} | php | public function setStatus($code, $reasonPhrase = null)
{
$this->code = (int) $code;
if ($reasonPhrase !== null) {
$this->reasonPhrase = $reasonPhrase;
} elseif (isset(Http::$codes[$this->code])) {
$this->reasonPhrase = Http::$codes[$this->code];
}
} | [
"public",
"function",
"setStatus",
"(",
"$",
"code",
",",
"$",
"reasonPhrase",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"code",
"=",
"(",
"int",
")",
"$",
"code",
";",
"if",
"(",
"$",
"reasonPhrase",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"... | Sets the status code and reason phrase. If no reason phrase is provided
the standard message according to the status code is used
@param integer $code
@param integer $reasonPhrase | [
"Sets",
"the",
"status",
"code",
"and",
"reason",
"phrase",
".",
"If",
"no",
"reason",
"phrase",
"is",
"provided",
"the",
"standard",
"message",
"according",
"to",
"the",
"status",
"code",
"is",
"used"
] | c54d7212cfb513df84f810429aa34c6ac9942c01 | https://github.com/apioo/psx-http/blob/c54d7212cfb513df84f810429aa34c6ac9942c01/src/Response.php#L82-L91 | train |
apioo/psx-http | src/Response.php | Response.toString | public function toString()
{
$response = Parser\ResponseParser::buildStatusLine($this) . Http::NEW_LINE;
$headers = Parser\ResponseParser::buildHeaderFromMessage($this);
foreach ($headers as $header) {
$response.= $header . Http::NEW_LINE;
}
$response.= Http::NEW_LINE;
$response.= (string) $this->getBody();
return $response;
} | php | public function toString()
{
$response = Parser\ResponseParser::buildStatusLine($this) . Http::NEW_LINE;
$headers = Parser\ResponseParser::buildHeaderFromMessage($this);
foreach ($headers as $header) {
$response.= $header . Http::NEW_LINE;
}
$response.= Http::NEW_LINE;
$response.= (string) $this->getBody();
return $response;
} | [
"public",
"function",
"toString",
"(",
")",
"{",
"$",
"response",
"=",
"Parser",
"\\",
"ResponseParser",
"::",
"buildStatusLine",
"(",
"$",
"this",
")",
".",
"Http",
"::",
"NEW_LINE",
";",
"$",
"headers",
"=",
"Parser",
"\\",
"ResponseParser",
"::",
"build... | Converts the response object to an http response string
@return string | [
"Converts",
"the",
"response",
"object",
"to",
"an",
"http",
"response",
"string"
] | c54d7212cfb513df84f810429aa34c6ac9942c01 | https://github.com/apioo/psx-http/blob/c54d7212cfb513df84f810429aa34c6ac9942c01/src/Response.php#L98-L111 | train |
cmsgears/module-core | common/models/resources/Category.php | Category.getRoot | public function getRoot() {
$parentTable = CoreTables::getTableName( CoreTables::TABLE_CATEGORY );
return $this->hasOne( Category::class, [ 'id' => 'rootId' ] )->from( "$parentTable as root" );
} | php | public function getRoot() {
$parentTable = CoreTables::getTableName( CoreTables::TABLE_CATEGORY );
return $this->hasOne( Category::class, [ 'id' => 'rootId' ] )->from( "$parentTable as root" );
} | [
"public",
"function",
"getRoot",
"(",
")",
"{",
"$",
"parentTable",
"=",
"CoreTables",
"::",
"getTableName",
"(",
"CoreTables",
"::",
"TABLE_CATEGORY",
")",
";",
"return",
"$",
"this",
"->",
"hasOne",
"(",
"Category",
"::",
"class",
",",
"[",
"'id'",
"=>",... | Return the root parent of the category.
@return Category | [
"Return",
"the",
"root",
"parent",
"of",
"the",
"category",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/Category.php#L223-L228 | train |
cmsgears/module-core | common/models/resources/Category.php | Category.findByParentId | public static function findByParentId( $parentId, $config = [] ) {
$limit = $config['limit'] ?? null;
return self::find()->where( 'parentId=:id', [ ':id' => $parentId ] )->limit($limit)->all();
} | php | public static function findByParentId( $parentId, $config = [] ) {
$limit = $config['limit'] ?? null;
return self::find()->where( 'parentId=:id', [ ':id' => $parentId ] )->limit($limit)->all();
} | [
"public",
"static",
"function",
"findByParentId",
"(",
"$",
"parentId",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"limit",
"=",
"$",
"config",
"[",
"'limit'",
"]",
"??",
"null",
";",
"return",
"self",
"::",
"find",
"(",
")",
"->",
"where",
... | Find and return the categories having given parent id.
@param string $parentId
@param array $config
@return Category[] | [
"Find",
"and",
"return",
"the",
"categories",
"having",
"given",
"parent",
"id",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/Category.php#L317-L321 | train |
cmsgears/module-core | common/models/resources/Category.php | Category.findFeaturedByType | public static function findFeaturedByType( $type, $config = [] ) {
$ignoreSite = isset( $config[ 'ignoreSite' ] ) ? $config[ 'ignoreSite' ] : false;
$order = isset( $config[ 'order' ] ) ? $config[ 'order' ] : [ 'name' => SORT_ASC ];
$limit = $config['limit'] ?? null;
if( static::isMultiSite() && !$ignoreSite ) {
$siteId = isset( $config[ 'siteId' ] ) ? $config[ 'siteId' ] : Yii::$app->core->siteId;
return static::find()->where( 'type=:type AND siteId=:siteId AND featured=1', [ ':type' => $type, ':siteId' => $siteId ] )->orderBy( $order )->limit($limit)->all();
}
else {
return static::find()->where( 'type=:type AND featured=1', [ ':type' => $type ] )->orderBy( $order )->limit( $limit )->all();
}
} | php | public static function findFeaturedByType( $type, $config = [] ) {
$ignoreSite = isset( $config[ 'ignoreSite' ] ) ? $config[ 'ignoreSite' ] : false;
$order = isset( $config[ 'order' ] ) ? $config[ 'order' ] : [ 'name' => SORT_ASC ];
$limit = $config['limit'] ?? null;
if( static::isMultiSite() && !$ignoreSite ) {
$siteId = isset( $config[ 'siteId' ] ) ? $config[ 'siteId' ] : Yii::$app->core->siteId;
return static::find()->where( 'type=:type AND siteId=:siteId AND featured=1', [ ':type' => $type, ':siteId' => $siteId ] )->orderBy( $order )->limit($limit)->all();
}
else {
return static::find()->where( 'type=:type AND featured=1', [ ':type' => $type ] )->orderBy( $order )->limit( $limit )->all();
}
} | [
"public",
"static",
"function",
"findFeaturedByType",
"(",
"$",
"type",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"ignoreSite",
"=",
"isset",
"(",
"$",
"config",
"[",
"'ignoreSite'",
"]",
")",
"?",
"$",
"config",
"[",
"'ignoreSite'",
"]",
":",
... | Find and return the featured categories for given type.
@param string $type
@param array $config
@return Category | [
"Find",
"and",
"return",
"the",
"featured",
"categories",
"for",
"given",
"type",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/resources/Category.php#L330-L346 | train |
rodrigoiii/skeleton-core | src/classes/Console/Commands/MakeRuleCommand.php | MakeRuleCommand.ruleTemplate | private function ruleTemplate($rule)
{
$file = __DIR__ . "/../templates/validator/rule.php.dist";
if (file_exists($file))
{
$template = strtr(file_get_contents($file), [
'{{namespace}}' => get_app_namespace(),
'{{rule}}' => $rule
]);
if (!file_exists(app_path("Validation/Rules")))
{
mkdir(app_path("Validation/Rules"), 0755, true);
}
$file_path = app_path("Validation/Rules/{$rule}.php");
$file = fopen($file_path, "w");
fwrite($file, $template);
fclose($file);
return file_exists($file_path);
}
return false;
} | php | private function ruleTemplate($rule)
{
$file = __DIR__ . "/../templates/validator/rule.php.dist";
if (file_exists($file))
{
$template = strtr(file_get_contents($file), [
'{{namespace}}' => get_app_namespace(),
'{{rule}}' => $rule
]);
if (!file_exists(app_path("Validation/Rules")))
{
mkdir(app_path("Validation/Rules"), 0755, true);
}
$file_path = app_path("Validation/Rules/{$rule}.php");
$file = fopen($file_path, "w");
fwrite($file, $template);
fclose($file);
return file_exists($file_path);
}
return false;
} | [
"private",
"function",
"ruleTemplate",
"(",
"$",
"rule",
")",
"{",
"$",
"file",
"=",
"__DIR__",
".",
"\"/../templates/validator/rule.php.dist\"",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"template",
"=",
"strtr",
"(",
"file_get_co... | Create the rule template.
@param string $rule
@return boolean | [
"Create",
"the",
"rule",
"template",
"."
] | 5dab0637b9cd0f55a64b1f5926d7ba6bb3f93df0 | https://github.com/rodrigoiii/skeleton-core/blob/5dab0637b9cd0f55a64b1f5926d7ba6bb3f93df0/src/classes/Console/Commands/MakeRuleCommand.php#L67-L93 | train |
Finesse/MicroDB | src/Connection.php | Connection.create | public static function create(
string $dsn,
string $username = null,
string $passwd = null,
array $options = null
): self {
$defaultOptions = [
\PDO::ATTR_STRINGIFY_FETCHES => false
];
try {
return new static(new \PDO($dsn, $username, $passwd, array_replace($defaultOptions, $options ?? [])));
} catch (\Throwable $exception) {
throw static::wrapException($exception);
}
} | php | public static function create(
string $dsn,
string $username = null,
string $passwd = null,
array $options = null
): self {
$defaultOptions = [
\PDO::ATTR_STRINGIFY_FETCHES => false
];
try {
return new static(new \PDO($dsn, $username, $passwd, array_replace($defaultOptions, $options ?? [])));
} catch (\Throwable $exception) {
throw static::wrapException($exception);
}
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"dsn",
",",
"string",
"$",
"username",
"=",
"null",
",",
"string",
"$",
"passwd",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"null",
")",
":",
"self",
"{",
"$",
"defaultOptions",
"=",
... | Creates a self instance. All the arguments are the arguments for the PDO constructor.
@param string $dsn
@param string|null $username
@param string|null $passwd
@param array|null $options
@return static
@throws PDOException
@see http://php.net/manual/en/pdo.construct.php Arguments reference | [
"Creates",
"a",
"self",
"instance",
".",
"All",
"the",
"arguments",
"are",
"the",
"arguments",
"for",
"the",
"PDO",
"constructor",
"."
] | 839ee9b2bbf7bf9811f946325ae7a0eb03d0c063 | https://github.com/Finesse/MicroDB/blob/839ee9b2bbf7bf9811f946325ae7a0eb03d0c063/src/Connection.php#L50-L65 | train |
Finesse/MicroDB | src/Connection.php | Connection.selectFirst | public function selectFirst(string $query, array $values = [])
{
try {
$row = $this->executeStatement($query, $values)->fetch();
return $row === false ? null : $row;
} catch (\Throwable $exception) {
throw static::wrapException($exception, $query, $values);
}
} | php | public function selectFirst(string $query, array $values = [])
{
try {
$row = $this->executeStatement($query, $values)->fetch();
return $row === false ? null : $row;
} catch (\Throwable $exception) {
throw static::wrapException($exception, $query, $values);
}
} | [
"public",
"function",
"selectFirst",
"(",
"string",
"$",
"query",
",",
"array",
"$",
"values",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"executeStatement",
"(",
"$",
"query",
",",
"$",
"values",
")",
"->",
"fetch",
"... | Performs a select query and returns the first query result.
@param string $query Full SQL query
@param array $values Values to bind. The indexes are the names or numbers of the values.
@return array|null An array indexed by columns. Null if nothing is found.
@throws InvalidArgumentException
@throws PDOException | [
"Performs",
"a",
"select",
"query",
"and",
"returns",
"the",
"first",
"query",
"result",
"."
] | 839ee9b2bbf7bf9811f946325ae7a0eb03d0c063 | https://github.com/Finesse/MicroDB/blob/839ee9b2bbf7bf9811f946325ae7a0eb03d0c063/src/Connection.php#L94-L102 | train |
Finesse/MicroDB | src/Connection.php | Connection.insert | public function insert(string $query, array $values = []): int
{
try {
return $this->executeStatement($query, $values)->rowCount();
} catch (\Throwable $exception) {
throw static::wrapException($exception, $query, $values);
}
} | php | public function insert(string $query, array $values = []): int
{
try {
return $this->executeStatement($query, $values)->rowCount();
} catch (\Throwable $exception) {
throw static::wrapException($exception, $query, $values);
}
} | [
"public",
"function",
"insert",
"(",
"string",
"$",
"query",
",",
"array",
"$",
"values",
"=",
"[",
"]",
")",
":",
"int",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"executeStatement",
"(",
"$",
"query",
",",
"$",
"values",
")",
"->",
"rowCount",
... | Performs an insert query and returns the number of inserted rows.
@param string $query Full SQL query
@param array $values Values to bind. The indexes are the names or numbers of the values.
@return int
@throws InvalidArgumentException
@throws PDOException | [
"Performs",
"an",
"insert",
"query",
"and",
"returns",
"the",
"number",
"of",
"inserted",
"rows",
"."
] | 839ee9b2bbf7bf9811f946325ae7a0eb03d0c063 | https://github.com/Finesse/MicroDB/blob/839ee9b2bbf7bf9811f946325ae7a0eb03d0c063/src/Connection.php#L113-L120 | train |
Finesse/MicroDB | src/Connection.php | Connection.insertGetId | public function insertGetId(string $query, array $values = [], string $sequence = null)
{
try {
$this->executeStatement($query, $values);
$id = $this->pdo->lastInsertId($sequence);
return is_numeric($id) ? (int)$id : $id;
} catch (\Throwable $exception) {
throw static::wrapException($exception, $query, $values);
}
} | php | public function insertGetId(string $query, array $values = [], string $sequence = null)
{
try {
$this->executeStatement($query, $values);
$id = $this->pdo->lastInsertId($sequence);
return is_numeric($id) ? (int)$id : $id;
} catch (\Throwable $exception) {
throw static::wrapException($exception, $query, $values);
}
} | [
"public",
"function",
"insertGetId",
"(",
"string",
"$",
"query",
",",
"array",
"$",
"values",
"=",
"[",
"]",
",",
"string",
"$",
"sequence",
"=",
"null",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"executeStatement",
"(",
"$",
"query",
",",
"$",
"valu... | Performs an insert query and returns the identifier of the last inserted row.
@param string $query Full SQL query
@param array $values Values to bind. The indexes are the names or numbers of the values.
@param string|null $sequence Name of the sequence object from which the ID should be returned
@return int|string
@throws InvalidArgumentException
@throws PDOException | [
"Performs",
"an",
"insert",
"query",
"and",
"returns",
"the",
"identifier",
"of",
"the",
"last",
"inserted",
"row",
"."
] | 839ee9b2bbf7bf9811f946325ae7a0eb03d0c063 | https://github.com/Finesse/MicroDB/blob/839ee9b2bbf7bf9811f946325ae7a0eb03d0c063/src/Connection.php#L132-L141 | train |
Finesse/MicroDB | src/Connection.php | Connection.statement | public function statement(string $query, array $values = [])
{
try {
$this->executeStatement($query, $values);
} catch (\Throwable $exception) {
throw static::wrapException($exception, $query, $values);
}
} | php | public function statement(string $query, array $values = [])
{
try {
$this->executeStatement($query, $values);
} catch (\Throwable $exception) {
throw static::wrapException($exception, $query, $values);
}
} | [
"public",
"function",
"statement",
"(",
"string",
"$",
"query",
",",
"array",
"$",
"values",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"executeStatement",
"(",
"$",
"query",
",",
"$",
"values",
")",
";",
"}",
"catch",
"(",
"\\",
"Thro... | Performs a general query. If the query contains multiple statements separated by a semicolon, only the first
statement will be executed.
@param string $query Full SQL query
@param array $values Values to bind. The indexes are the names or numbers of the values.
@throws InvalidArgumentException
@throws PDOException | [
"Performs",
"a",
"general",
"query",
".",
"If",
"the",
"query",
"contains",
"multiple",
"statements",
"separated",
"by",
"a",
"semicolon",
"only",
"the",
"first",
"statement",
"will",
"be",
"executed",
"."
] | 839ee9b2bbf7bf9811f946325ae7a0eb03d0c063 | https://github.com/Finesse/MicroDB/blob/839ee9b2bbf7bf9811f946325ae7a0eb03d0c063/src/Connection.php#L188-L195 | train |
Finesse/MicroDB | src/Connection.php | Connection.executeStatement | protected function executeStatement(string $query, array $values = []): \PDOStatement
{
$statement = $this->pdo->prepare($query);
$this->bindValues($statement, $values);
$statement->execute();
return $statement;
} | php | protected function executeStatement(string $query, array $values = []): \PDOStatement
{
$statement = $this->pdo->prepare($query);
$this->bindValues($statement, $values);
$statement->execute();
return $statement;
} | [
"protected",
"function",
"executeStatement",
"(",
"string",
"$",
"query",
",",
"array",
"$",
"values",
"=",
"[",
"]",
")",
":",
"\\",
"PDOStatement",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"pdo",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
... | Executes a single SQL statement and returns the corresponding PDO statement.
@param string $query Full SQL query
@param array $values Values to bind. The indexes are the names or numbers of the values.
@return \PDOStatement
@throws InvalidArgumentException
@throws BasePDOException | [
"Executes",
"a",
"single",
"SQL",
"statement",
"and",
"returns",
"the",
"corresponding",
"PDO",
"statement",
"."
] | 839ee9b2bbf7bf9811f946325ae7a0eb03d0c063 | https://github.com/Finesse/MicroDB/blob/839ee9b2bbf7bf9811f946325ae7a0eb03d0c063/src/Connection.php#L260-L266 | train |
Finesse/MicroDB | src/Connection.php | Connection.bindValues | protected function bindValues(\PDOStatement $statement, array $values)
{
$number = 1;
foreach ($values as $name => $value) {
$this->bindValue($statement, is_string($name) ? $name : $number, $value);
$number += 1;
}
} | php | protected function bindValues(\PDOStatement $statement, array $values)
{
$number = 1;
foreach ($values as $name => $value) {
$this->bindValue($statement, is_string($name) ? $name : $number, $value);
$number += 1;
}
} | [
"protected",
"function",
"bindValues",
"(",
"\\",
"PDOStatement",
"$",
"statement",
",",
"array",
"$",
"values",
")",
"{",
"$",
"number",
"=",
"1",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->"... | Binds parameters to a PDO statement.
@param \PDOStatement $statement PDO statement
@param array $values Parameters. The indexes are the names or numbers of the values.
@throws InvalidArgumentException
@throws BasePDOException | [
"Binds",
"parameters",
"to",
"a",
"PDO",
"statement",
"."
] | 839ee9b2bbf7bf9811f946325ae7a0eb03d0c063 | https://github.com/Finesse/MicroDB/blob/839ee9b2bbf7bf9811f946325ae7a0eb03d0c063/src/Connection.php#L276-L284 | train |
Finesse/MicroDB | src/Connection.php | Connection.bindValue | protected function bindValue(\PDOStatement $statement, $name, $value)
{
if ($value !== null && !is_scalar($value)) {
throw new InvalidArgumentException(sprintf(
'Bound value %s expected to be scalar or null, a %s given',
is_int($name) ? '#'.$name : '`'.$name.'`',
gettype($value)
));
}
if ($value === null) {
$type = \PDO::PARAM_NULL;
} elseif (is_bool($value)) {
$type = \PDO::PARAM_BOOL;
} elseif (is_integer($value)) {
$type = \PDO::PARAM_INT;
} else {
$type = \PDO::PARAM_STR;
}
$statement->bindValue($name, $value, $type);
} | php | protected function bindValue(\PDOStatement $statement, $name, $value)
{
if ($value !== null && !is_scalar($value)) {
throw new InvalidArgumentException(sprintf(
'Bound value %s expected to be scalar or null, a %s given',
is_int($name) ? '#'.$name : '`'.$name.'`',
gettype($value)
));
}
if ($value === null) {
$type = \PDO::PARAM_NULL;
} elseif (is_bool($value)) {
$type = \PDO::PARAM_BOOL;
} elseif (is_integer($value)) {
$type = \PDO::PARAM_INT;
} else {
$type = \PDO::PARAM_STR;
}
$statement->bindValue($name, $value, $type);
} | [
"protected",
"function",
"bindValue",
"(",
"\\",
"PDOStatement",
"$",
"statement",
",",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"null",
"&&",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"Inval... | Binds a value to a PDO statement.
@param \PDOStatement $statement PDO statement
@param string|int $name Value placeholder name or index (if the placeholder is not named)
@param string|int|float|boolean|null $value Value to bind
@throws InvalidArgumentException
@throws BasePDOException | [
"Binds",
"a",
"value",
"to",
"a",
"PDO",
"statement",
"."
] | 839ee9b2bbf7bf9811f946325ae7a0eb03d0c063 | https://github.com/Finesse/MicroDB/blob/839ee9b2bbf7bf9811f946325ae7a0eb03d0c063/src/Connection.php#L295-L316 | train |
Finesse/MicroDB | src/Connection.php | Connection.makeReadResource | protected function makeReadResource($source)
{
if (is_resource($source)) {
return $source;
}
if (is_string($source)) {
$resource = @fopen($source, 'r');
if ($resource) {
return $resource;
}
$errorInfo = error_get_last();
throw new FileException(sprintf(
'Unable to open the file `%s` for reading%s',
$source,
$errorInfo ? ': '.$errorInfo['message'] : ''
));
}
throw new InvalidArgumentException(sprintf(
'The given source expected to be a file path of a resource, a %s given',
is_object($source) ? get_class($source).' instance' : gettype($source)
));
} | php | protected function makeReadResource($source)
{
if (is_resource($source)) {
return $source;
}
if (is_string($source)) {
$resource = @fopen($source, 'r');
if ($resource) {
return $resource;
}
$errorInfo = error_get_last();
throw new FileException(sprintf(
'Unable to open the file `%s` for reading%s',
$source,
$errorInfo ? ': '.$errorInfo['message'] : ''
));
}
throw new InvalidArgumentException(sprintf(
'The given source expected to be a file path of a resource, a %s given',
is_object($source) ? get_class($source).' instance' : gettype($source)
));
} | [
"protected",
"function",
"makeReadResource",
"(",
"$",
"source",
")",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"source",
")",
")",
"{",
"return",
"$",
"source",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"source",
")",
")",
"{",
"$",
"resource",
"="... | Makes a resource for reading data.
@param string|resource $source A file path or a read resource
@return resource
@throws FileException
@throws InvalidArgumentException | [
"Makes",
"a",
"resource",
"for",
"reading",
"data",
"."
] | 839ee9b2bbf7bf9811f946325ae7a0eb03d0c063 | https://github.com/Finesse/MicroDB/blob/839ee9b2bbf7bf9811f946325ae7a0eb03d0c063/src/Connection.php#L326-L351 | train |
Finesse/MicroDB | src/Connection.php | Connection.wrapException | protected static function wrapException(
\Throwable $exception,
string $query = null,
array $values = null
): \Throwable {
if ($exception instanceof BasePDOException) {
return PDOException::wrapBaseException($exception, $query, $values);
}
return $exception;
} | php | protected static function wrapException(
\Throwable $exception,
string $query = null,
array $values = null
): \Throwable {
if ($exception instanceof BasePDOException) {
return PDOException::wrapBaseException($exception, $query, $values);
}
return $exception;
} | [
"protected",
"static",
"function",
"wrapException",
"(",
"\\",
"Throwable",
"$",
"exception",
",",
"string",
"$",
"query",
"=",
"null",
",",
"array",
"$",
"values",
"=",
"null",
")",
":",
"\\",
"Throwable",
"{",
"if",
"(",
"$",
"exception",
"instanceof",
... | Creates a library exception from a PHP exception if possible.
@param \Throwable $exception
@param string|null $query SQL query which caused the error (if caused by a query)
@param array|null $values Bound values (if caused by a query)
@return IException|\Throwable | [
"Creates",
"a",
"library",
"exception",
"from",
"a",
"PHP",
"exception",
"if",
"possible",
"."
] | 839ee9b2bbf7bf9811f946325ae7a0eb03d0c063 | https://github.com/Finesse/MicroDB/blob/839ee9b2bbf7bf9811f946325ae7a0eb03d0c063/src/Connection.php#L361-L371 | train |
Innmind/AMQP | src/Model/Queue/Declaration.php | Declaration.passive | public static function passive(string $name): self
{
$self = new self;
$self->passive = true;
return $self->withName($name);
} | php | public static function passive(string $name): self
{
$self = new self;
$self->passive = true;
return $self->withName($name);
} | [
"public",
"static",
"function",
"passive",
"(",
"string",
"$",
"name",
")",
":",
"self",
"{",
"$",
"self",
"=",
"new",
"self",
";",
"$",
"self",
"->",
"passive",
"=",
"true",
";",
"return",
"$",
"self",
"->",
"withName",
"(",
"$",
"name",
")",
";",... | Check if the queue exists on the server | [
"Check",
"if",
"the",
"queue",
"exists",
"on",
"the",
"server"
] | c22b3a8f56162f7845a13c149cb3118e5fe7cffd | https://github.com/Innmind/AMQP/blob/c22b3a8f56162f7845a13c149cb3118e5fe7cffd/src/Model/Queue/Declaration.php#L34-L40 | train |
Innmind/AMQP | src/Model/Queue/Declaration.php | Declaration.exclusive | public function exclusive(): self
{
if ($this->isPassive()) {
throw new ExclusivePassiveDeclarationNotAllowed;
}
$self = clone $this;
$self->exclusive = true;
return $self;
} | php | public function exclusive(): self
{
if ($this->isPassive()) {
throw new ExclusivePassiveDeclarationNotAllowed;
}
$self = clone $this;
$self->exclusive = true;
return $self;
} | [
"public",
"function",
"exclusive",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"isPassive",
"(",
")",
")",
"{",
"throw",
"new",
"ExclusivePassiveDeclarationNotAllowed",
";",
"}",
"$",
"self",
"=",
"clone",
"$",
"this",
";",
"$",
"self",
"... | Make the queue only accessible to the current connection | [
"Make",
"the",
"queue",
"only",
"accessible",
"to",
"the",
"current",
"connection"
] | c22b3a8f56162f7845a13c149cb3118e5fe7cffd | https://github.com/Innmind/AMQP/blob/c22b3a8f56162f7845a13c149cb3118e5fe7cffd/src/Model/Queue/Declaration.php#L75-L85 | train |
Innmind/AMQP | src/Model/Queue/Declaration.php | Declaration.dontWait | public function dontWait(): self
{
if ($this->isPassive()) {
throw new NotWaitingPassiveDeclarationDoesNothing;
}
$self = clone $this;
$self->wait = false;
return $self;
} | php | public function dontWait(): self
{
if ($this->isPassive()) {
throw new NotWaitingPassiveDeclarationDoesNothing;
}
$self = clone $this;
$self->wait = false;
return $self;
} | [
"public",
"function",
"dontWait",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"isPassive",
"(",
")",
")",
"{",
"throw",
"new",
"NotWaitingPassiveDeclarationDoesNothing",
";",
"}",
"$",
"self",
"=",
"clone",
"$",
"this",
";",
"$",
"self",
... | Don't wait for the server response | [
"Don",
"t",
"wait",
"for",
"the",
"server",
"response"
] | c22b3a8f56162f7845a13c149cb3118e5fe7cffd | https://github.com/Innmind/AMQP/blob/c22b3a8f56162f7845a13c149cb3118e5fe7cffd/src/Model/Queue/Declaration.php#L101-L111 | train |
Innmind/AMQP | src/Model/Queue/Declaration.php | Declaration.withName | public function withName(string $name): self
{
$self = clone $this;
$self->name = $name;
return $self;
} | php | public function withName(string $name): self
{
$self = clone $this;
$self->name = $name;
return $self;
} | [
"public",
"function",
"withName",
"(",
"string",
"$",
"name",
")",
":",
"self",
"{",
"$",
"self",
"=",
"clone",
"$",
"this",
";",
"$",
"self",
"->",
"name",
"=",
"$",
"name",
";",
"return",
"$",
"self",
";",
"}"
] | Name the queue with the given string | [
"Name",
"the",
"queue",
"with",
"the",
"given",
"string"
] | c22b3a8f56162f7845a13c149cb3118e5fe7cffd | https://github.com/Innmind/AMQP/blob/c22b3a8f56162f7845a13c149cb3118e5fe7cffd/src/Model/Queue/Declaration.php#L127-L133 | train |
Innmind/AMQP | src/Model/Queue/Declaration.php | Declaration.withAutoGeneratedName | public function withAutoGeneratedName(): self
{
if ($this->isPassive()) {
throw new PassiveQueueDeclarationMustHaveAName;
}
$self = clone $this;
$self->name = null;
return $self;
} | php | public function withAutoGeneratedName(): self
{
if ($this->isPassive()) {
throw new PassiveQueueDeclarationMustHaveAName;
}
$self = clone $this;
$self->name = null;
return $self;
} | [
"public",
"function",
"withAutoGeneratedName",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"isPassive",
"(",
")",
")",
"{",
"throw",
"new",
"PassiveQueueDeclarationMustHaveAName",
";",
"}",
"$",
"self",
"=",
"clone",
"$",
"this",
";",
"$",
... | Let the server generate a name for the queue | [
"Let",
"the",
"server",
"generate",
"a",
"name",
"for",
"the",
"queue"
] | c22b3a8f56162f7845a13c149cb3118e5fe7cffd | https://github.com/Innmind/AMQP/blob/c22b3a8f56162f7845a13c149cb3118e5fe7cffd/src/Model/Queue/Declaration.php#L138-L148 | train |
cmsgears/module-core | common/models/forms/Login.php | Login.validatePassword | public function validatePassword( $attribute, $params ) {
if( !$this->hasErrors() ) {
$user = $this->getUser();
if( $user && !$user->validatePassword( $this->password ) ) {
$this->addError( $attribute, Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_LOGIN_FAILED ) );
}
}
} | php | public function validatePassword( $attribute, $params ) {
if( !$this->hasErrors() ) {
$user = $this->getUser();
if( $user && !$user->validatePassword( $this->password ) ) {
$this->addError( $attribute, Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_LOGIN_FAILED ) );
}
}
} | [
"public",
"function",
"validatePassword",
"(",
"$",
"attribute",
",",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasErrors",
"(",
")",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"$",
"use... | Check whether the password provided by user is valid.
@param string $attribute
@param array $params | [
"Check",
"whether",
"the",
"password",
"provided",
"by",
"user",
"is",
"valid",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/forms/Login.php#L171-L182 | train |
cmsgears/module-core | common/models/forms/Login.php | Login.getUser | public function getUser() {
// Find user having email or username
if( empty( $this->user ) ) {
$this->user = $this->userService->getByEmail( $this->email );
if( empty( $this->user ) ) {
$this->user = $this->userService->getByUsername( $this->email );
}
}
return $this->user;
} | php | public function getUser() {
// Find user having email or username
if( empty( $this->user ) ) {
$this->user = $this->userService->getByEmail( $this->email );
if( empty( $this->user ) ) {
$this->user = $this->userService->getByUsername( $this->email );
}
}
return $this->user;
} | [
"public",
"function",
"getUser",
"(",
")",
"{",
"// Find user having email or username",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"user",
")",
")",
"{",
"$",
"this",
"->",
"user",
"=",
"$",
"this",
"->",
"userService",
"->",
"getByEmail",
"(",
"$",
"t... | Find and return the user using given email or username.
@return \cmsgears\core\common\models\entities\User | [
"Find",
"and",
"return",
"the",
"user",
"using",
"given",
"email",
"or",
"username",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/forms/Login.php#L191-L205 | train |
cmsgears/module-core | common/models/forms/Login.php | Login.login | public function login() {
if ( $this->validate() ) {
$user = $this->getUser();
if( $this->admin ) {
$user->loadPermissions();
if( !$user->isPermitted( CoreGlobal::PERM_ADMIN ) ) {
$this->addError( "email", Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_NOT_ALLOWED ) );
return false;
}
}
$user->lastLoginAt = DateUtil::getDateTime();
$user->save();
return Yii::$app->user->login( $user, $this->rememberMe ? $this->interval : 0 );
}
return false;
} | php | public function login() {
if ( $this->validate() ) {
$user = $this->getUser();
if( $this->admin ) {
$user->loadPermissions();
if( !$user->isPermitted( CoreGlobal::PERM_ADMIN ) ) {
$this->addError( "email", Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_NOT_ALLOWED ) );
return false;
}
}
$user->lastLoginAt = DateUtil::getDateTime();
$user->save();
return Yii::$app->user->login( $user, $this->rememberMe ? $this->interval : 0 );
}
return false;
} | [
"public",
"function",
"login",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"validate",
"(",
")",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"admin",
")",
"{",
"$",
"user",
"->",
"lo... | Login and remember the user for pre-defined interval.
@return boolean | [
"Login",
"and",
"remember",
"the",
"user",
"for",
"pre",
"-",
"defined",
"interval",
"."
] | ce1b1f7afff2931847d71afa152c72355f374dc6 | https://github.com/cmsgears/module-core/blob/ce1b1f7afff2931847d71afa152c72355f374dc6/common/models/forms/Login.php#L212-L238 | train |
spiral/exceptions | src/Style/HtmlStyle.php | HtmlStyle.getStyle | private function getStyle(array $token, array $previous): string
{
if (!empty($previous)) {
foreach ($this->style as $style => $tokens) {
if (in_array($previous[1] . $token[0], $tokens)) {
return $style;
}
}
}
foreach ($this->style as $style => $tokens) {
if (in_array($token[0], $tokens)) {
return $style;
}
}
return '';
} | php | private function getStyle(array $token, array $previous): string
{
if (!empty($previous)) {
foreach ($this->style as $style => $tokens) {
if (in_array($previous[1] . $token[0], $tokens)) {
return $style;
}
}
}
foreach ($this->style as $style => $tokens) {
if (in_array($token[0], $tokens)) {
return $style;
}
}
return '';
} | [
"private",
"function",
"getStyle",
"(",
"array",
"$",
"token",
",",
"array",
"$",
"previous",
")",
":",
"string",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"previous",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"style",
"as",
"$",
"style",
"=>... | Get styles for a given token.
@param array $token
@param array $previous
@return string | [
"Get",
"styles",
"for",
"a",
"given",
"token",
"."
] | 9735a00b189ce61317cd49a9d6ec630f68cee381 | https://github.com/spiral/exceptions/blob/9735a00b189ce61317cd49a9d6ec630f68cee381/src/Style/HtmlStyle.php#L214-L231 | train |
hiqdev/yii2-hiam-authclient | src/Collection.php | Collection.getClient | public function getClient($id = null)
{
if ($id === null) {
$id = array_keys($this->getClients())[0];
}
return parent::getClient($id);
} | php | public function getClient($id = null)
{
if ($id === null) {
$id = array_keys($this->getClients())[0];
}
return parent::getClient($id);
} | [
"public",
"function",
"getClient",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"id",
"===",
"null",
")",
"{",
"$",
"id",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"getClients",
"(",
")",
")",
"[",
"0",
"]",
";",
"}",
"return",
"pare... | Gets first client by default. | [
"Gets",
"first",
"client",
"by",
"default",
"."
] | c0ef62196a1fde499cfa4d85e76e04dc26e41559 | https://github.com/hiqdev/yii2-hiam-authclient/blob/c0ef62196a1fde499cfa4d85e76e04dc26e41559/src/Collection.php#L19-L26 | train |
mcaskill/charcoal-support | src/Cms/Metatag/DocumentTrait.php | DocumentTrait.parseDocumentTitle | protected function parseDocumentTitle(array $parts)
{
$parts = $this->parseDocumentTitleParts($parts);
$delim = $this->parseDocumentTitleSeparator();
$title = implode($delim, $parts);
return $title;
} | php | protected function parseDocumentTitle(array $parts)
{
$parts = $this->parseDocumentTitleParts($parts);
$delim = $this->parseDocumentTitleSeparator();
$title = implode($delim, $parts);
return $title;
} | [
"protected",
"function",
"parseDocumentTitle",
"(",
"array",
"$",
"parts",
")",
"{",
"$",
"parts",
"=",
"$",
"this",
"->",
"parseDocumentTitleParts",
"(",
"$",
"parts",
")",
";",
"$",
"delim",
"=",
"$",
"this",
"->",
"parseDocumentTitleSeparator",
"(",
")",
... | Parse the document title.
@param array $parts The document title parts.
@return string The concatenated title. | [
"Parse",
"the",
"document",
"title",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/Metatag/DocumentTrait.php#L56-L63 | train |
mcaskill/charcoal-support | src/Cms/Metatag/DocumentTrait.php | DocumentTrait.parseDocumentTitleParts | protected function parseDocumentTitleParts(array $parts)
{
$segments = [];
foreach ($parts as $key => $value) {
$value = $this->parseDocumentTitlePart($value, $key, $parts);
if ($value === true) {
$value = $parts[$key];
}
if (is_bool($value) || (empty($value) && !is_numeric($value))) {
continue;
}
$segments[$key] = (string)$value;
}
return $segments;
} | php | protected function parseDocumentTitleParts(array $parts)
{
$segments = [];
foreach ($parts as $key => $value) {
$value = $this->parseDocumentTitlePart($value, $key, $parts);
if ($value === true) {
$value = $parts[$key];
}
if (is_bool($value) || (empty($value) && !is_numeric($value))) {
continue;
}
$segments[$key] = (string)$value;
}
return $segments;
} | [
"protected",
"function",
"parseDocumentTitleParts",
"(",
"array",
"$",
"parts",
")",
"{",
"$",
"segments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"parseD... | Parse the document title segments.
Iterates over each value in $parts passing them to
{@see DocumentTrait::filterDocumentTitlePart}.
If the method returns TRUE, the current value from $parts
is concatenated into the title.
@param array $parts The document title parts.
@return array The parsed and filtered segments. | [
"Parse",
"the",
"document",
"title",
"segments",
"."
] | 2138a34463ca6865bf3a60635aa11381a9ae73c5 | https://github.com/mcaskill/charcoal-support/blob/2138a34463ca6865bf3a60635aa11381a9ae73c5/src/Cms/Metatag/DocumentTrait.php#L76-L93 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/ModelStructureProperty.php | ModelStructureProperty.structureMetadata | public function structureMetadata()
{
if ($this->structureMetadata === null || $this->isStructureFinalized === false) {
$this->structureMetadata = $this->loadStructureMetadata();
}
return $this->structureMetadata;
} | php | public function structureMetadata()
{
if ($this->structureMetadata === null || $this->isStructureFinalized === false) {
$this->structureMetadata = $this->loadStructureMetadata();
}
return $this->structureMetadata;
} | [
"public",
"function",
"structureMetadata",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"structureMetadata",
"===",
"null",
"||",
"$",
"this",
"->",
"isStructureFinalized",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"structureMetadata",
"=",
"$",
"this",
... | Retrieve the property's structure.
@return MetadataInterface|null | [
"Retrieve",
"the",
"property",
"s",
"structure",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/ModelStructureProperty.php#L172-L179 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/ModelStructureProperty.php | ModelStructureProperty.setStructureMetadata | public function setStructureMetadata($data)
{
if ($data === null) {
$this->structureMetadata = $data;
$this->terminalStructureMetadata = $data;
} elseif (is_array($data)) {
$struct = $this->createStructureMetadata();
$struct->merge($data);
$this->structureMetadata = $struct;
$this->terminalStructureMetadata = $data;
} elseif ($data instanceof MetadataInterface) {
$this->structureMetadata = $data;
$this->terminalStructureMetadata = $data;
} else {
throw new InvalidArgumentException(sprintf(
'Structure [%s] is invalid (must be array or an instance of %s).',
(is_object($data) ? get_class($data) : gettype($data)),
StructureMetadata::class
));
}
$this->isStructureFinalized = false;
return $this;
} | php | public function setStructureMetadata($data)
{
if ($data === null) {
$this->structureMetadata = $data;
$this->terminalStructureMetadata = $data;
} elseif (is_array($data)) {
$struct = $this->createStructureMetadata();
$struct->merge($data);
$this->structureMetadata = $struct;
$this->terminalStructureMetadata = $data;
} elseif ($data instanceof MetadataInterface) {
$this->structureMetadata = $data;
$this->terminalStructureMetadata = $data;
} else {
throw new InvalidArgumentException(sprintf(
'Structure [%s] is invalid (must be array or an instance of %s).',
(is_object($data) ? get_class($data) : gettype($data)),
StructureMetadata::class
));
}
$this->isStructureFinalized = false;
return $this;
} | [
"public",
"function",
"setStructureMetadata",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"structureMetadata",
"=",
"$",
"data",
";",
"$",
"this",
"->",
"terminalStructureMetadata",
"=",
"$",
"data",
";... | Set the property's structure.
@param MetadataInterface|array|null $data The property's structure (fields, data).
@throws InvalidArgumentException If the structure is invalid.
@return self | [
"Set",
"the",
"property",
"s",
"structure",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/ModelStructureProperty.php#L188-L213 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/ModelStructureProperty.php | ModelStructureProperty.addStructureInterface | public function addStructureInterface($interface)
{
if (!is_string($interface)) {
throw new InvalidArgumentException(sprintf(
'Structure interface must to be a string, received %s',
is_object($interface) ? get_class($interface) : gettype($interface)
));
}
if (!empty($interface)) {
$interface = $this->parseStructureInterface($interface);
$this->structureInterfaces[$interface] = true;
$this->isStructureFinalized = false;
}
return $this;
} | php | public function addStructureInterface($interface)
{
if (!is_string($interface)) {
throw new InvalidArgumentException(sprintf(
'Structure interface must to be a string, received %s',
is_object($interface) ? get_class($interface) : gettype($interface)
));
}
if (!empty($interface)) {
$interface = $this->parseStructureInterface($interface);
$this->structureInterfaces[$interface] = true;
$this->isStructureFinalized = false;
}
return $this;
} | [
"public",
"function",
"addStructureInterface",
"(",
"$",
"interface",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"interface",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Structure interface must to be a string, received %s'"... | Add the given metadata interfaces for the property to use as a structure.
@param string $interface A metadata interface to use.
@throws InvalidArgumentException If the interface is not a string.
@return self | [
"Add",
"the",
"given",
"metadata",
"interfaces",
"for",
"the",
"property",
"to",
"use",
"as",
"a",
"structure",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/ModelStructureProperty.php#L266-L283 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/ModelStructureProperty.php | ModelStructureProperty.loadStructureMetadata | protected function loadStructureMetadata()
{
$structureMetadata = null;
if ($this->isStructureFinalized === false) {
$this->isStructureFinalized = true;
$structureInterfaces = $this->structureInterfaces();
if (!empty($structureInterfaces)) {
$metadataLoader = $this->metadataLoader();
$metadataClass = $this->structureMetadataClass();
$structureKey = $structureInterfaces;
array_unshift($structureKey, $this->ident());
$structureKey = 'property/structure='.$metadataLoader->serializeMetaKey($structureKey);
$structureMetadata = $metadataLoader->load(
$structureKey,
$metadataClass,
$structureInterfaces
);
}
}
if ($structureMetadata === null) {
$structureMetadata = $this->createStructureMetadata();
}
if ($this->terminalStructureMetadata) {
$structureMetadata->merge($this->terminalStructureMetadata);
}
return $structureMetadata;
} | php | protected function loadStructureMetadata()
{
$structureMetadata = null;
if ($this->isStructureFinalized === false) {
$this->isStructureFinalized = true;
$structureInterfaces = $this->structureInterfaces();
if (!empty($structureInterfaces)) {
$metadataLoader = $this->metadataLoader();
$metadataClass = $this->structureMetadataClass();
$structureKey = $structureInterfaces;
array_unshift($structureKey, $this->ident());
$structureKey = 'property/structure='.$metadataLoader->serializeMetaKey($structureKey);
$structureMetadata = $metadataLoader->load(
$structureKey,
$metadataClass,
$structureInterfaces
);
}
}
if ($structureMetadata === null) {
$structureMetadata = $this->createStructureMetadata();
}
if ($this->terminalStructureMetadata) {
$structureMetadata->merge($this->terminalStructureMetadata);
}
return $structureMetadata;
} | [
"protected",
"function",
"loadStructureMetadata",
"(",
")",
"{",
"$",
"structureMetadata",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"isStructureFinalized",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"isStructureFinalized",
"=",
"true",
";",
"$",
"st... | Load the property's structure.
@return MetadataInterface | [
"Load",
"the",
"property",
"s",
"structure",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/ModelStructureProperty.php#L290-L323 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/ModelStructureProperty.php | ModelStructureProperty.structureProto | public function structureProto()
{
if ($this->structurePrototype === null) {
$model = $this->createStructureModel();
if ($model instanceof DescribableInterface) {
$model->setMetadata($this->structureMetadata());
}
$this->structurePrototype = $model;
}
return $this->structurePrototype;
} | php | public function structureProto()
{
if ($this->structurePrototype === null) {
$model = $this->createStructureModel();
if ($model instanceof DescribableInterface) {
$model->setMetadata($this->structureMetadata());
}
$this->structurePrototype = $model;
}
return $this->structurePrototype;
} | [
"public",
"function",
"structureProto",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"structurePrototype",
"===",
"null",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"createStructureModel",
"(",
")",
";",
"if",
"(",
"$",
"model",
"instanceof",
"Descr... | Retrieve a singleton of the structure model for prototyping.
@return ArrayAccess|DescribableInterface | [
"Retrieve",
"a",
"singleton",
"of",
"the",
"structure",
"model",
"for",
"prototyping",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/ModelStructureProperty.php#L331-L344 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/ModelStructureProperty.php | ModelStructureProperty.structureVal | public function structureVal($val, $options = [])
{
if ($val === null) {
return ($this->multiple() ? [] : null);
}
$metadata = clone $this->structureMetadata();
if ($options instanceof MetadataInterface) {
$metadata->merge($options);
} elseif ($options === null) {
$options = [];
} elseif (is_array($options)) {
if (isset($options['metadata'])) {
$metadata->merge($options['metadata']);
}
} else {
throw new InvalidArgumentException(sprintf(
'Structure value options must to be an array or an instance of %2$s, received %1$s',
is_object($options) ? get_class($options) : gettype($options),
StructureMetadata::class
));
}
$defaultData = [];
if (isset($options['default_data'])) {
if (is_bool($options['default_data'])) {
$withDefaultData = $options['default_data'];
if ($withDefaultData) {
$defaultData = $metadata->defaultData();
}
} elseif (is_array($options['default_data'])) {
$withDefaultData = true;
$defaultData = $options['default_data'];
}
}
$val = $this->parseVal($val);
if ($this->multiple()) {
$entries = [];
foreach ($val as $v) {
$entries[] = $this->createStructureModelWith($metadata, $defaultData, $v);
}
return $entries;
} else {
return $this->createStructureModelWith($metadata, $defaultData, $val);
}
} | php | public function structureVal($val, $options = [])
{
if ($val === null) {
return ($this->multiple() ? [] : null);
}
$metadata = clone $this->structureMetadata();
if ($options instanceof MetadataInterface) {
$metadata->merge($options);
} elseif ($options === null) {
$options = [];
} elseif (is_array($options)) {
if (isset($options['metadata'])) {
$metadata->merge($options['metadata']);
}
} else {
throw new InvalidArgumentException(sprintf(
'Structure value options must to be an array or an instance of %2$s, received %1$s',
is_object($options) ? get_class($options) : gettype($options),
StructureMetadata::class
));
}
$defaultData = [];
if (isset($options['default_data'])) {
if (is_bool($options['default_data'])) {
$withDefaultData = $options['default_data'];
if ($withDefaultData) {
$defaultData = $metadata->defaultData();
}
} elseif (is_array($options['default_data'])) {
$withDefaultData = true;
$defaultData = $options['default_data'];
}
}
$val = $this->parseVal($val);
if ($this->multiple()) {
$entries = [];
foreach ($val as $v) {
$entries[] = $this->createStructureModelWith($metadata, $defaultData, $v);
}
return $entries;
} else {
return $this->createStructureModelWith($metadata, $defaultData, $val);
}
} | [
"public",
"function",
"structureVal",
"(",
"$",
"val",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"val",
"===",
"null",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"multiple",
"(",
")",
"?",
"[",
"]",
":",
"null",
")",
";",
... | Convert the given value into a structure.
Options:
- `default_data` (_boolean_|_array_) — If TRUE, the default data defined
in the structure's metadata is merged. If an array, that is merged.
@param mixed $val The value to "structurize".
@param array|MetadataInterface $options Optional structure options.
@throws InvalidArgumentException If the options are invalid.
@return ModelInterface|ModelInterface[] | [
"Convert",
"the",
"given",
"value",
"into",
"a",
"structure",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/ModelStructureProperty.php#L388-L437 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/ModelStructureProperty.php | ModelStructureProperty.structureModelFactory | protected function structureModelFactory()
{
if (!isset($this->structureModelFactory)) {
throw new RuntimeException(sprintf(
'Model Factory is not defined for "%s"',
get_class($this)
));
}
return $this->structureModelFactory;
} | php | protected function structureModelFactory()
{
if (!isset($this->structureModelFactory)) {
throw new RuntimeException(sprintf(
'Model Factory is not defined for "%s"',
get_class($this)
));
}
return $this->structureModelFactory;
} | [
"protected",
"function",
"structureModelFactory",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"structureModelFactory",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Model Factory is not defined for \"%s\"'",
",",
"ge... | Retrieve the structure model factory.
@throws RuntimeException If the model factory was not previously set.
@return FactoryInterface | [
"Retrieve",
"the",
"structure",
"model",
"factory",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/ModelStructureProperty.php#L527-L537 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/IdProperty.php | IdProperty.setMode | public function setMode($mode)
{
$availableModes = $this->availableModes();
if (!in_array($mode, $availableModes)) {
throw new InvalidArgumentException(sprintf(
'Invalid ID mode. Must be one of "%s"',
implode(', ', $availableModes)
));
}
$this->mode = $mode;
return $this;
} | php | public function setMode($mode)
{
$availableModes = $this->availableModes();
if (!in_array($mode, $availableModes)) {
throw new InvalidArgumentException(sprintf(
'Invalid ID mode. Must be one of "%s"',
implode(', ', $availableModes)
));
}
$this->mode = $mode;
return $this;
} | [
"public",
"function",
"setMode",
"(",
"$",
"mode",
")",
"{",
"$",
"availableModes",
"=",
"$",
"this",
"->",
"availableModes",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"mode",
",",
"$",
"availableModes",
")",
")",
"{",
"throw",
"new",
"Inv... | Set the allowed ID mode.
@param string $mode The ID mode ("auto-increment", "custom", "uniqid" or "uuid").
@throws InvalidArgumentException If the mode is not one of the 4 valid modes.
@return self | [
"Set",
"the",
"allowed",
"ID",
"mode",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/IdProperty.php#L134-L147 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/IdProperty.php | IdProperty.autoGenerate | public function autoGenerate()
{
$mode = $this->mode();
if ($mode === self::MODE_UNIQID) {
return uniqid();
} elseif ($mode === self::MODE_UUID) {
return $this->generateUuid();
}
return null;
} | php | public function autoGenerate()
{
$mode = $this->mode();
if ($mode === self::MODE_UNIQID) {
return uniqid();
} elseif ($mode === self::MODE_UUID) {
return $this->generateUuid();
}
return null;
} | [
"public",
"function",
"autoGenerate",
"(",
")",
"{",
"$",
"mode",
"=",
"$",
"this",
"->",
"mode",
"(",
")",
";",
"if",
"(",
"$",
"mode",
"===",
"self",
"::",
"MODE_UNIQID",
")",
"{",
"return",
"uniqid",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"mo... | Auto-generate a value upon first save.
- self::MODE_AUTOINCREMENT
- null: The auto-generated value should be handled at the database driver level.
- self::MODE_CUSTOM
- null: Custom mode must be defined elsewhere.
- self::MODE_UNIQID
- A random 13-char `uniqid()` value.
- self::MODE_UUID
- A random RFC-4122 UUID value.
@throws DomainException If the mode does not have a value generator.
@return string|null | [
"Auto",
"-",
"generate",
"a",
"value",
"upon",
"first",
"save",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/IdProperty.php#L191-L202 | train |
locomotivemtl/charcoal-property | src/Charcoal/Property/IdProperty.php | IdProperty.sqlPdoType | public function sqlPdoType()
{
$mode = $this->mode();
if ($mode === self::MODE_AUTO_INCREMENT) {
return PDO::PARAM_INT;
} else {
return PDO::PARAM_STR;
}
} | php | public function sqlPdoType()
{
$mode = $this->mode();
if ($mode === self::MODE_AUTO_INCREMENT) {
return PDO::PARAM_INT;
} else {
return PDO::PARAM_STR;
}
} | [
"public",
"function",
"sqlPdoType",
"(",
")",
"{",
"$",
"mode",
"=",
"$",
"this",
"->",
"mode",
"(",
")",
";",
"if",
"(",
"$",
"mode",
"===",
"self",
"::",
"MODE_AUTO_INCREMENT",
")",
"{",
"return",
"PDO",
"::",
"PARAM_INT",
";",
"}",
"else",
"{",
... | Get the PDO data type.
@see StorablePropertyTrait::sqlPdoType()
@return integer | [
"Get",
"the",
"PDO",
"data",
"type",
"."
] | 5ff339a0edb78a909537a9d2bb7f9b783255316b | https://github.com/locomotivemtl/charcoal-property/blob/5ff339a0edb78a909537a9d2bb7f9b783255316b/src/Charcoal/Property/IdProperty.php#L287-L296 | train |
nails/module-email | src/Service/Emailer.php | Emailer.discoverTypes | public static function discoverTypes(array &$aArray): void
{
$aLocations = [
NAILS_COMMON_PATH . 'config/email_types.php',
];
foreach (Components::modules() as $oModule) {
$aLocations[] = $oModule->path . $oModule->moduleName . '/config/email_types.php';
}
$aLocations[] = NAILS_APP_PATH . 'application/config/email_types.php';
foreach ($aLocations as $sPath) {
static::loadTypes($sPath, $aArray);
}
} | php | public static function discoverTypes(array &$aArray): void
{
$aLocations = [
NAILS_COMMON_PATH . 'config/email_types.php',
];
foreach (Components::modules() as $oModule) {
$aLocations[] = $oModule->path . $oModule->moduleName . '/config/email_types.php';
}
$aLocations[] = NAILS_APP_PATH . 'application/config/email_types.php';
foreach ($aLocations as $sPath) {
static::loadTypes($sPath, $aArray);
}
} | [
"public",
"static",
"function",
"discoverTypes",
"(",
"array",
"&",
"$",
"aArray",
")",
":",
"void",
"{",
"$",
"aLocations",
"=",
"[",
"NAILS_COMMON_PATH",
".",
"'config/email_types.php'",
",",
"]",
";",
"foreach",
"(",
"Components",
"::",
"modules",
"(",
")... | Auto-discover all emails supplied by modules and the app
@param array $aArray The array to populate with discoveries | [
"Auto",
"-",
"discover",
"all",
"emails",
"supplied",
"by",
"modules",
"and",
"the",
"app"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L96-L111 | train |
nails/module-email | src/Service/Emailer.php | Emailer.addType | protected static function addType(\stdClass $oData, array &$aArray): bool
{
if (!empty($oData->slug) && !empty($oData->template_body)) {
$aArray[$oData->slug] = (object) [
'slug' => $oData->slug,
'name' => $oData->name,
'description' => $oData->description,
'isUnsubscribable' => property_exists($oData, 'isUnsubscribable') ? (bool) $oData->isUnsubscribable : true,
'template_header' => empty($oData->template_header) ? 'email/structure/header' : $oData->template_header,
'template_body' => $oData->template_body,
'template_footer' => empty($oData->template_footer) ? 'email/structure/footer' : $oData->template_footer,
'default_subject' => $oData->default_subject,
];
return true;
}
return false;
} | php | protected static function addType(\stdClass $oData, array &$aArray): bool
{
if (!empty($oData->slug) && !empty($oData->template_body)) {
$aArray[$oData->slug] = (object) [
'slug' => $oData->slug,
'name' => $oData->name,
'description' => $oData->description,
'isUnsubscribable' => property_exists($oData, 'isUnsubscribable') ? (bool) $oData->isUnsubscribable : true,
'template_header' => empty($oData->template_header) ? 'email/structure/header' : $oData->template_header,
'template_body' => $oData->template_body,
'template_footer' => empty($oData->template_footer) ? 'email/structure/footer' : $oData->template_footer,
'default_subject' => $oData->default_subject,
];
return true;
}
return false;
} | [
"protected",
"static",
"function",
"addType",
"(",
"\\",
"stdClass",
"$",
"oData",
",",
"array",
"&",
"$",
"aArray",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"oData",
"->",
"slug",
")",
"&&",
"!",
"empty",
"(",
"$",
"oData",
"->",
... | Adds a new email type to the stack
@param \stdClass $oData An object representing the email type
@param array $aArray The array to populate
@return boolean | [
"Adds",
"a",
"new",
"email",
"type",
"to",
"the",
"stack"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L158-L177 | train |
nails/module-email | src/Service/Emailer.php | Emailer.resend | public function resend($mEmailIdRef)
{
if (is_numeric($mEmailIdRef)) {
$oEmail = $this->getById($mEmailIdRef);
} else {
$oEmail = $this->getByRef($mEmailIdRef);
}
if (empty($oEmail)) {
$this->setError('"' . $mEmailIdRef . '" is not a valid Email ID or reference.');
return false;
}
return $this->doSend($oEmail);
} | php | public function resend($mEmailIdRef)
{
if (is_numeric($mEmailIdRef)) {
$oEmail = $this->getById($mEmailIdRef);
} else {
$oEmail = $this->getByRef($mEmailIdRef);
}
if (empty($oEmail)) {
$this->setError('"' . $mEmailIdRef . '" is not a valid Email ID or reference.');
return false;
}
return $this->doSend($oEmail);
} | [
"public",
"function",
"resend",
"(",
"$",
"mEmailIdRef",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"mEmailIdRef",
")",
")",
"{",
"$",
"oEmail",
"=",
"$",
"this",
"->",
"getById",
"(",
"$",
"mEmailIdRef",
")",
";",
"}",
"else",
"{",
"$",
"oEmail",
... | Sends an email again
@todo This should probably create a new row
@param mixed $mEmailIdRef The email's ID or ref
@return boolean
@throws EmailerException | [
"Sends",
"an",
"email",
"again"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L372-L386 | train |
nails/module-email | src/Service/Emailer.php | Emailer.userHasUnsubscribed | public function userHasUnsubscribed($iUSerId, $sType)
{
$oDb = Factory::service('Database');
$oDb->where('user_id', $iUSerId);
$oDb->where('type', $sType);
return (bool) $oDb->count_all_results(NAILS_DB_PREFIX . 'user_email_blocker');
} | php | public function userHasUnsubscribed($iUSerId, $sType)
{
$oDb = Factory::service('Database');
$oDb->where('user_id', $iUSerId);
$oDb->where('type', $sType);
return (bool) $oDb->count_all_results(NAILS_DB_PREFIX . 'user_email_blocker');
} | [
"public",
"function",
"userHasUnsubscribed",
"(",
"$",
"iUSerId",
",",
"$",
"sType",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"where",
"(",
"'user_id'",
",",
"$",
"iUSerId",
")",
";",
"$",
... | Determines whether the user has unsubscribed from this email type
@param int $iUSerId The user ID to check for
@param string $sType The type of email to check against
@return boolean
@throws \Nails\Common\Exception\FactoryException | [
"Determines",
"whether",
"the",
"user",
"has",
"unsubscribed",
"from",
"this",
"email",
"type"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L399-L405 | train |
nails/module-email | src/Service/Emailer.php | Emailer.userIsSuspended | public function userIsSuspended($iUserId)
{
$oDb = Factory::service('Database');
$oDb->where('id', $iUserId);
$oDb->where('is_suspended', true);
return (bool) $oDb->count_all_results(NAILS_DB_PREFIX . 'user');
} | php | public function userIsSuspended($iUserId)
{
$oDb = Factory::service('Database');
$oDb->where('id', $iUserId);
$oDb->where('is_suspended', true);
return (bool) $oDb->count_all_results(NAILS_DB_PREFIX . 'user');
} | [
"public",
"function",
"userIsSuspended",
"(",
"$",
"iUserId",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"where",
"(",
"'id'",
",",
"$",
"iUserId",
")",
";",
"$",
"oDb",
"->",
"where",
"(",
... | Determiens whether a suer is suspended
@param integer $iUserId The user ID to check
@return bool
@throws \Nails\Common\Exception\FactoryException | [
"Determiens",
"whether",
"a",
"suer",
"is",
"suspended"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L417-L423 | train |
nails/module-email | src/Service/Emailer.php | Emailer.unsubscribeUser | public function unsubscribeUser($user_id, $type)
{
if ($this->userHasUnsubscribed($user_id, $type)) {
return true;
}
// --------------------------------------------------------------------------
$oDb = Factory::service('Database');
$oDb->set('user_id', $user_id);
$oDb->set('type', $type);
$oDb->set('created', 'NOW()', false);
$oDb->insert(NAILS_DB_PREFIX . 'user_email_blocker');
return (bool) $oDb->affected_rows();
} | php | public function unsubscribeUser($user_id, $type)
{
if ($this->userHasUnsubscribed($user_id, $type)) {
return true;
}
// --------------------------------------------------------------------------
$oDb = Factory::service('Database');
$oDb->set('user_id', $user_id);
$oDb->set('type', $type);
$oDb->set('created', 'NOW()', false);
$oDb->insert(NAILS_DB_PREFIX . 'user_email_blocker');
return (bool) $oDb->affected_rows();
} | [
"public",
"function",
"unsubscribeUser",
"(",
"$",
"user_id",
",",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"userHasUnsubscribed",
"(",
"$",
"user_id",
",",
"$",
"type",
")",
")",
"{",
"return",
"true",
";",
"}",
"// ---------------------------... | Unsubscribes a user from a particular email type
@param int $user_id The user ID to unsubscribe
@param string $type The type of email to unsubscribe from
@return boolean
@throws \Nails\Common\Exception\FactoryException | [
"Unsubscribes",
"a",
"user",
"from",
"a",
"particular",
"email",
"type"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L436-L451 | train |
nails/module-email | src/Service/Emailer.php | Emailer.subscribeUser | public function subscribeUser($user_id, $type)
{
if (!$this->userHasUnsubscribed($user_id, $type)) {
return true;
}
// --------------------------------------------------------------------------
$oDb = Factory::service('Database');
$oDb->where('user_id', $user_id);
$oDb->where('type', $type);
$oDb->delete(NAILS_DB_PREFIX . 'user_email_blocker');
return (bool) $oDb->affected_rows();
} | php | public function subscribeUser($user_id, $type)
{
if (!$this->userHasUnsubscribed($user_id, $type)) {
return true;
}
// --------------------------------------------------------------------------
$oDb = Factory::service('Database');
$oDb->where('user_id', $user_id);
$oDb->where('type', $type);
$oDb->delete(NAILS_DB_PREFIX . 'user_email_blocker');
return (bool) $oDb->affected_rows();
} | [
"public",
"function",
"subscribeUser",
"(",
"$",
"user_id",
",",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"userHasUnsubscribed",
"(",
"$",
"user_id",
",",
"$",
"type",
")",
")",
"{",
"return",
"true",
";",
"}",
"// ----------------------... | Subscribe a user to a particular email type
@param int $user_id The user ID to subscribe
@param string $type The type of email to subscribe to
@return boolean
@throws \Nails\Common\Exception\FactoryException | [
"Subscribe",
"a",
"user",
"to",
"a",
"particular",
"email",
"type"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L464-L478 | train |
nails/module-email | src/Service/Emailer.php | Emailer.getAllRawQuery | public function getAllRawQuery($page = null, $perPage = null, $data = [])
{
$oDb = Factory::service('Database');
$oDb->select('ea.id,ea.ref,ea.type,ea.email_vars,ea.user_email sent_to,ue.is_verified email_verified');
$oDb->select('ue.code email_verified_code,ea.sent,ea.status,ea.read_count,ea.link_click_count');
$oDb->select('u.first_name,u.last_name,u.id user_id,u.password user_password,u.group_id user_group');
$oDb->select('u.profile_img,u.gender,u.username');
// Apply common items; pass $data
$this->getCountCommonEmail($data);
// --------------------------------------------------------------------------
// Facilitate pagination
if (!is_null($page)) {
/**
* Adjust the page variable, reduce by one so that the offset is calculated
* correctly. Make sure we don't go into negative numbers
*/
$page--;
$page = $page < 0 ? 0 : $page;
// Work out what the offset should be
$perPage = is_null($perPage) ? 50 : (int) $perPage;
$offset = $page * $perPage;
$oDb->limit($perPage, $offset);
}
return $oDb->get($this->sTable . ' ' . $this->sTableAlias);
} | php | public function getAllRawQuery($page = null, $perPage = null, $data = [])
{
$oDb = Factory::service('Database');
$oDb->select('ea.id,ea.ref,ea.type,ea.email_vars,ea.user_email sent_to,ue.is_verified email_verified');
$oDb->select('ue.code email_verified_code,ea.sent,ea.status,ea.read_count,ea.link_click_count');
$oDb->select('u.first_name,u.last_name,u.id user_id,u.password user_password,u.group_id user_group');
$oDb->select('u.profile_img,u.gender,u.username');
// Apply common items; pass $data
$this->getCountCommonEmail($data);
// --------------------------------------------------------------------------
// Facilitate pagination
if (!is_null($page)) {
/**
* Adjust the page variable, reduce by one so that the offset is calculated
* correctly. Make sure we don't go into negative numbers
*/
$page--;
$page = $page < 0 ? 0 : $page;
// Work out what the offset should be
$perPage = is_null($perPage) ? 50 : (int) $perPage;
$offset = $page * $perPage;
$oDb->limit($perPage, $offset);
}
return $oDb->get($this->sTable . ' ' . $this->sTableAlias);
} | [
"public",
"function",
"getAllRawQuery",
"(",
"$",
"page",
"=",
"null",
",",
"$",
"perPage",
"=",
"null",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"select"... | Returns emails from the archive
@param integer $page The page of results to retrieve
@param integer $perPage The number of results per page
@param array $data Data to pass to getCountCommonEmail()
@return object
@throws \Nails\Common\Exception\FactoryException | [
"Returns",
"emails",
"from",
"the",
"archive"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L720-L752 | train |
nails/module-email | src/Service/Emailer.php | Emailer.getAll | public function getAll($iPage = null, $iPerPage = null, $aData = [])
{
$oResults = $this->getAllRawQuery($iPage, $iPerPage, $aData);
$aResults = $oResults->result();
$numResults = count($aResults);
for ($i = 0; $i < $numResults; $i++) {
$this->formatObject($aResults[$i]);
}
return $aResults;
} | php | public function getAll($iPage = null, $iPerPage = null, $aData = [])
{
$oResults = $this->getAllRawQuery($iPage, $iPerPage, $aData);
$aResults = $oResults->result();
$numResults = count($aResults);
for ($i = 0; $i < $numResults; $i++) {
$this->formatObject($aResults[$i]);
}
return $aResults;
} | [
"public",
"function",
"getAll",
"(",
"$",
"iPage",
"=",
"null",
",",
"$",
"iPerPage",
"=",
"null",
",",
"$",
"aData",
"=",
"[",
"]",
")",
"{",
"$",
"oResults",
"=",
"$",
"this",
"->",
"getAllRawQuery",
"(",
"$",
"iPage",
",",
"$",
"iPerPage",
",",
... | Fetches all emails from the archive and formats them, optionally paginated
@param int $iPage The page number of the results, if null then no pagination
@param int $iPerPage How many items per page of paginated results
@param mixed $aData Any data to pass to getCountCommon()
@return array
@throws \Nails\Common\Exception\FactoryException | [
"Fetches",
"all",
"emails",
"from",
"the",
"archive",
"and",
"formats",
"them",
"optionally",
"paginated"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L766-L777 | train |
nails/module-email | src/Service/Emailer.php | Emailer.countAll | public function countAll($data)
{
$this->getCountCommonEmail($data);
$oDb = Factory::service('Database');
return $oDb->count_all_results($this->sTable . ' ' . $this->sTableAlias);
} | php | public function countAll($data)
{
$this->getCountCommonEmail($data);
$oDb = Factory::service('Database');
return $oDb->count_all_results($this->sTable . ' ' . $this->sTableAlias);
} | [
"public",
"function",
"countAll",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"getCountCommonEmail",
"(",
"$",
"data",
")",
";",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"return",
"$",
"oDb",
"->",
"count_all_results",... | Count the number of records in the archive
@param array $data Data passed from the calling method
@return mixed
@throws \Nails\Common\Exception\FactoryException | [
"Count",
"the",
"number",
"of",
"records",
"in",
"the",
"archive"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L856-L861 | train |
nails/module-email | src/Service/Emailer.php | Emailer.getById | public function getById($iId, $aData = [])
{
if (empty($aData['where'])) {
$aData['where'] = [];
}
$aData['where'][] = [$this->sTableAlias . '.id', $iId];
$aEmails = $this->getAll(null, null, $aData);
return !empty($aEmails) ? reset($aEmails) : false;
} | php | public function getById($iId, $aData = [])
{
if (empty($aData['where'])) {
$aData['where'] = [];
}
$aData['where'][] = [$this->sTableAlias . '.id', $iId];
$aEmails = $this->getAll(null, null, $aData);
return !empty($aEmails) ? reset($aEmails) : false;
} | [
"public",
"function",
"getById",
"(",
"$",
"iId",
",",
"$",
"aData",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"aData",
"[",
"'where'",
"]",
")",
")",
"{",
"$",
"aData",
"[",
"'where'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"aData",... | Get en email from the archive by its ID
@param int $iId The email's ID
@param array $aData The data array
@return mixed stdClass on success, false on failure
@throws \Nails\Common\Exception\FactoryException | [
"Get",
"en",
"email",
"from",
"the",
"archive",
"by",
"its",
"ID"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L874-L885 | train |
nails/module-email | src/Service/Emailer.php | Emailer.getByRef | public function getByRef($sRef, $aData = [])
{
if (empty($aData['where'])) {
$aData['where'] = [];
}
$aData['where'][] = [$this->sTableAlias . '.ref', $sRef];
$aEmails = $this->getAll(null, null, $aData);
return !empty($aEmails) ? reset($aEmails) : false;
} | php | public function getByRef($sRef, $aData = [])
{
if (empty($aData['where'])) {
$aData['where'] = [];
}
$aData['where'][] = [$this->sTableAlias . '.ref', $sRef];
$aEmails = $this->getAll(null, null, $aData);
return !empty($aEmails) ? reset($aEmails) : false;
} | [
"public",
"function",
"getByRef",
"(",
"$",
"sRef",
",",
"$",
"aData",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"aData",
"[",
"'where'",
"]",
")",
")",
"{",
"$",
"aData",
"[",
"'where'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"aData... | Get an email from the archive by its reference
@param string $sRef The email's reference
@param array $aData The data array
@return mixed stdClass on success, false on failure
@throws \Nails\Common\Exception\FactoryException | [
"Get",
"an",
"email",
"from",
"the",
"archive",
"by",
"its",
"reference"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L898-L909 | train |
nails/module-email | src/Service/Emailer.php | Emailer.validateHash | public function validateHash($sRef, $sGuid, $sHash)
{
return isAdmin() || $this->generateHash($sRef, $sGuid) === $sHash;
} | php | public function validateHash($sRef, $sGuid, $sHash)
{
return isAdmin() || $this->generateHash($sRef, $sGuid) === $sHash;
} | [
"public",
"function",
"validateHash",
"(",
"$",
"sRef",
",",
"$",
"sGuid",
",",
"$",
"sHash",
")",
"{",
"return",
"isAdmin",
"(",
")",
"||",
"$",
"this",
"->",
"generateHash",
"(",
"$",
"sRef",
",",
"$",
"sGuid",
")",
"===",
"$",
"sHash",
";",
"}"
... | Validates an email hash
@param string $sRef The email's ref
@param string $sGuid The email's guid
@param string $sHash The hash to validate
@return bool | [
"Validates",
"an",
"email",
"hash"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L922-L925 | train |
nails/module-email | src/Service/Emailer.php | Emailer.generateReference | protected function generateReference($exclude = [])
{
$oDb = Factory::service('Database');
do {
$refOk = false;
do {
$ref = strtoupper(random_string('alnum', 10));
if (array_search($ref, $exclude) === false) {
$refOk = true;
}
} while (!$refOk);
$oDb->where('ref', $ref);
$result = $oDb->get($this->sTable);
} while ($result->num_rows());
return $ref;
} | php | protected function generateReference($exclude = [])
{
$oDb = Factory::service('Database');
do {
$refOk = false;
do {
$ref = strtoupper(random_string('alnum', 10));
if (array_search($ref, $exclude) === false) {
$refOk = true;
}
} while (!$refOk);
$oDb->where('ref', $ref);
$result = $oDb->get($this->sTable);
} while ($result->num_rows());
return $ref;
} | [
"protected",
"function",
"generateReference",
"(",
"$",
"exclude",
"=",
"[",
"]",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"do",
"{",
"$",
"refOk",
"=",
"false",
";",
"do",
"{",
"$",
"ref",
"=",
"strtoupper"... | Generates a unique reference for an email, optionally exclude strings
@param array $exclude Strings to exclude from the reference
@return string
@throws \Nails\Common\Exception\FactoryException | [
"Generates",
"a",
"unique",
"reference",
"for",
"an",
"email",
"optionally",
"exclude",
"strings"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L971-L994 | train |
nails/module-email | src/Service/Emailer.php | Emailer.printDebugger | protected function printDebugger($input, $body, $plaintext, $recent_errors)
{
/**
* Debug mode, output data and don't actually send
* Remove the reference to CI; takes up a ton'na space
*/
if (isset($input->data['ci'])) {
$input->data['ci'] = '**REFERENCE TO CODEIGNITER INSTANCE**';
}
// --------------------------------------------------------------------------
// Input variables
echo '<pre>';
// Who's the email going to?
echo '<strong>Sending to:</strong>' . "\n";
echo '-----------------------------------------------------------------' . "\n";
echo 'email: ' . $input->to->email . "\n";
echo 'first: ' . $input->to->first . "\n";
echo 'last: ' . $input->to->last . "\n";
// Who's the email being sent from?
echo "\n\n" . '<strong>Sending from:</strong>' . "\n";
echo '-----------------------------------------------------------------' . "\n";
echo 'name: ' . $input->from->name . "\n";
echo 'email: ' . $input->from->email . "\n";
// Input data (system & supplied)
echo "\n\n" . '<strong>Input variables (supplied + system):</strong>' . "\n";
echo '-----------------------------------------------------------------' . "\n";
print_r($input->data);
// Template
echo "\n\n" . '<strong>Email body:</strong>' . "\n";
echo '-----------------------------------------------------------------' . "\n";
echo 'Subject: ' . $input->subject . "\n";
echo 'Template Header: ' . $input->template_header . "\n";
echo 'Template Body: ' . $input->template_body . "\n";
echo 'Template Footer: ' . $input->template_footer . "\n";
if ($recent_errors) {
echo "\n\n" . '<strong>Template Errors (' . count($recent_errors) . '):</strong>' . "\n";
echo '-----------------------------------------------------------------' . "\n";
foreach ($recent_errors as $error) {
echo 'Severity: ' . $error->severity . "\n";
echo 'Mesage: ' . $error->message . "\n";
echo 'Filepath: ' . $error->filepath . "\n";
echo 'Line: ' . $error->line . "\n\n";
}
}
echo "\n\n" . '<strong>Rendered HTML:</strong>' . "\n";
echo '-----------------------------------------------------------------' . "\n";
$_rendered_body = str_replace('"', '\\"', $body);
$_rendered_body = str_replace(["\r\n", "\r"], "\n", $_rendered_body);
$_lines = explode("\n", $_rendered_body);
$_new_lines = [];
foreach ($_lines as $line) {
if (!empty($line)) {
$_new_lines[] = $line;
}
}
$renderedBody = implode($_new_lines);
$entityBody = htmlentities($body);
$plaintextBody = nl2br($plaintext);
$str = <<<EOT
<iframe width="100%" height="900" src="" id="renderframe"></iframe>
<script type="text/javascript">
var emailBody = "$renderedBody";
document.getElementById('renderframe').src = "data:text/html;charset=utf-8," + escape(emailBody);
</script>
<strong>HTML:</strong>
-----------------------------------------------------------------
$entityBody
<strong>Plain Text:</strong>
-----------------------------------------------------------------
</pre>$plaintextBody</pre>
EOT;
} | php | protected function printDebugger($input, $body, $plaintext, $recent_errors)
{
/**
* Debug mode, output data and don't actually send
* Remove the reference to CI; takes up a ton'na space
*/
if (isset($input->data['ci'])) {
$input->data['ci'] = '**REFERENCE TO CODEIGNITER INSTANCE**';
}
// --------------------------------------------------------------------------
// Input variables
echo '<pre>';
// Who's the email going to?
echo '<strong>Sending to:</strong>' . "\n";
echo '-----------------------------------------------------------------' . "\n";
echo 'email: ' . $input->to->email . "\n";
echo 'first: ' . $input->to->first . "\n";
echo 'last: ' . $input->to->last . "\n";
// Who's the email being sent from?
echo "\n\n" . '<strong>Sending from:</strong>' . "\n";
echo '-----------------------------------------------------------------' . "\n";
echo 'name: ' . $input->from->name . "\n";
echo 'email: ' . $input->from->email . "\n";
// Input data (system & supplied)
echo "\n\n" . '<strong>Input variables (supplied + system):</strong>' . "\n";
echo '-----------------------------------------------------------------' . "\n";
print_r($input->data);
// Template
echo "\n\n" . '<strong>Email body:</strong>' . "\n";
echo '-----------------------------------------------------------------' . "\n";
echo 'Subject: ' . $input->subject . "\n";
echo 'Template Header: ' . $input->template_header . "\n";
echo 'Template Body: ' . $input->template_body . "\n";
echo 'Template Footer: ' . $input->template_footer . "\n";
if ($recent_errors) {
echo "\n\n" . '<strong>Template Errors (' . count($recent_errors) . '):</strong>' . "\n";
echo '-----------------------------------------------------------------' . "\n";
foreach ($recent_errors as $error) {
echo 'Severity: ' . $error->severity . "\n";
echo 'Mesage: ' . $error->message . "\n";
echo 'Filepath: ' . $error->filepath . "\n";
echo 'Line: ' . $error->line . "\n\n";
}
}
echo "\n\n" . '<strong>Rendered HTML:</strong>' . "\n";
echo '-----------------------------------------------------------------' . "\n";
$_rendered_body = str_replace('"', '\\"', $body);
$_rendered_body = str_replace(["\r\n", "\r"], "\n", $_rendered_body);
$_lines = explode("\n", $_rendered_body);
$_new_lines = [];
foreach ($_lines as $line) {
if (!empty($line)) {
$_new_lines[] = $line;
}
}
$renderedBody = implode($_new_lines);
$entityBody = htmlentities($body);
$plaintextBody = nl2br($plaintext);
$str = <<<EOT
<iframe width="100%" height="900" src="" id="renderframe"></iframe>
<script type="text/javascript">
var emailBody = "$renderedBody";
document.getElementById('renderframe').src = "data:text/html;charset=utf-8," + escape(emailBody);
</script>
<strong>HTML:</strong>
-----------------------------------------------------------------
$entityBody
<strong>Plain Text:</strong>
-----------------------------------------------------------------
</pre>$plaintextBody</pre>
EOT;
} | [
"protected",
"function",
"printDebugger",
"(",
"$",
"input",
",",
"$",
"body",
",",
"$",
"plaintext",
",",
"$",
"recent_errors",
")",
"{",
"/**\n * Debug mode, output data and don't actually send\n * Remove the reference to CI; takes up a ton'na space\n */",... | Renders the debugger
@param \stdClass $input The email input object
@param string $body The email's body
@param string $plaintext The email's plaintext body
@param array $recent_errors An array of any recent errors
@return void | [
"Renders",
"the",
"debugger"
] | 42183b33a0465ab302f66a7b4f881410275eb6a4 | https://github.com/nails/module-email/blob/42183b33a0465ab302f66a7b4f881410275eb6a4/src/Service/Emailer.php#L1008-L1099 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.