id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
29,600
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Services/IdentResultsService.php
IdentResultsService.process
private function process(IdentResult &$result) { if (isset($result->person)) { foreach ($result->person as $p) { $attachments = $p->attachments; if (!empty($attachments)) { foreach ($attachments as $attachment) { $this->initMediaResource($attachment); } } } } }
php
private function process(IdentResult &$result) { if (isset($result->person)) { foreach ($result->person as $p) { $attachments = $p->attachments; if (!empty($attachments)) { foreach ($attachments as $attachment) { $this->initMediaResource($attachment); } } } } }
[ "private", "function", "process", "(", "IdentResult", "&", "$", "result", ")", "{", "if", "(", "isset", "(", "$", "result", "->", "person", ")", ")", "{", "foreach", "(", "$", "result", "->", "person", "as", "$", "p", ")", "{", "$", "attachments", "=", "$", "p", "->", "attachments", ";", "if", "(", "!", "empty", "(", "$", "attachments", ")", ")", "{", "foreach", "(", "$", "attachments", "as", "$", "attachment", ")", "{", "$", "this", "->", "initMediaResource", "(", "$", "attachment", ")", ";", "}", "}", "}", "}", "}" ]
Handles proper attachments initialization after retrieval of a ident result. @param IdentResult $result
[ "Handles", "proper", "attachments", "initialization", "after", "retrieval", "of", "a", "ident", "result", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Services/IdentResultsService.php#L79-L91
29,601
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.array_compare
public static function array_compare(&$arr1, &$arr2) { // Obviously bad data. if (! \is_array($arr1) || ! \is_array($arr2)) { return false; } $length = \count($arr1); // Length mismatch. if (\count($arr2) !== $length) { return false; } // Different keys, we don't need to check further. if (\count(\array_intersect_key($arr1, $arr2)) !== $length) { return false; } // We will ignore keys for non-associative arrays. if ( (cast::array_type($arr1) !== 'associative') && (cast::array_type($arr2) !== 'associative') ) { return \count(\array_intersect($arr1, $arr2)) === $length; } // Check each item. foreach ($arr1 as $k=>$v) { if (! isset($arr2[$k])) { return false; } // Recursive? if (\is_array($arr1[$k]) && \is_array($arr2[$k])) { if (! static::array_compare($arr1[$k], $arr2[$k])) { return false; } } elseif ($arr1[$k] !== $arr2[$k]) { return false; } } return true; }
php
public static function array_compare(&$arr1, &$arr2) { // Obviously bad data. if (! \is_array($arr1) || ! \is_array($arr2)) { return false; } $length = \count($arr1); // Length mismatch. if (\count($arr2) !== $length) { return false; } // Different keys, we don't need to check further. if (\count(\array_intersect_key($arr1, $arr2)) !== $length) { return false; } // We will ignore keys for non-associative arrays. if ( (cast::array_type($arr1) !== 'associative') && (cast::array_type($arr2) !== 'associative') ) { return \count(\array_intersect($arr1, $arr2)) === $length; } // Check each item. foreach ($arr1 as $k=>$v) { if (! isset($arr2[$k])) { return false; } // Recursive? if (\is_array($arr1[$k]) && \is_array($arr2[$k])) { if (! static::array_compare($arr1[$k], $arr2[$k])) { return false; } } elseif ($arr1[$k] !== $arr2[$k]) { return false; } } return true; }
[ "public", "static", "function", "array_compare", "(", "&", "$", "arr1", ",", "&", "$", "arr2", ")", "{", "// Obviously bad data.", "if", "(", "!", "\\", "is_array", "(", "$", "arr1", ")", "||", "!", "\\", "is_array", "(", "$", "arr2", ")", ")", "{", "return", "false", ";", "}", "$", "length", "=", "\\", "count", "(", "$", "arr1", ")", ";", "// Length mismatch.", "if", "(", "\\", "count", "(", "$", "arr2", ")", "!==", "$", "length", ")", "{", "return", "false", ";", "}", "// Different keys, we don't need to check further.", "if", "(", "\\", "count", "(", "\\", "array_intersect_key", "(", "$", "arr1", ",", "$", "arr2", ")", ")", "!==", "$", "length", ")", "{", "return", "false", ";", "}", "// We will ignore keys for non-associative arrays.", "if", "(", "(", "cast", "::", "array_type", "(", "$", "arr1", ")", "!==", "'associative'", ")", "&&", "(", "cast", "::", "array_type", "(", "$", "arr2", ")", "!==", "'associative'", ")", ")", "{", "return", "\\", "count", "(", "\\", "array_intersect", "(", "$", "arr1", ",", "$", "arr2", ")", ")", "===", "$", "length", ";", "}", "// Check each item.", "foreach", "(", "$", "arr1", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "!", "isset", "(", "$", "arr2", "[", "$", "k", "]", ")", ")", "{", "return", "false", ";", "}", "// Recursive?", "if", "(", "\\", "is_array", "(", "$", "arr1", "[", "$", "k", "]", ")", "&&", "\\", "is_array", "(", "$", "arr2", "[", "$", "k", "]", ")", ")", "{", "if", "(", "!", "static", "::", "array_compare", "(", "$", "arr1", "[", "$", "k", "]", ",", "$", "arr2", "[", "$", "k", "]", ")", ")", "{", "return", "false", ";", "}", "}", "elseif", "(", "$", "arr1", "[", "$", "k", "]", "!==", "$", "arr2", "[", "$", "k", "]", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Compare Two Arrays @param array $arr1 Array. @param array $arr2 Array. @return bool True/false.
[ "Compare", "Two", "Arrays" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L22-L66
29,602
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.array_pop
public static function array_pop(array &$arr) { if (! \count($arr)) { return false; } $reversed = \array_reverse($arr); return static::array_pop_top($reversed); }
php
public static function array_pop(array &$arr) { if (! \count($arr)) { return false; } $reversed = \array_reverse($arr); return static::array_pop_top($reversed); }
[ "public", "static", "function", "array_pop", "(", "array", "&", "$", "arr", ")", "{", "if", "(", "!", "\\", "count", "(", "$", "arr", ")", ")", "{", "return", "false", ";", "}", "$", "reversed", "=", "\\", "array_reverse", "(", "$", "arr", ")", ";", "return", "static", "::", "array_pop_top", "(", "$", "reversed", ")", ";", "}" ]
Return the last value of an array. This is like array_pop() but non-destructive. @param array $arr Array. @return mixed Value. False on error.
[ "Return", "the", "last", "value", "of", "an", "array", "." ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L275-L282
29,603
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.array_pop_rand
public static function array_pop_rand(array &$arr) { $length = \count($arr); if (! $length) { return false; } // Nothing random about an array with one thing. if (1 === $length) { return static::array_pop_top($arr); } $keys = \array_keys($arr); $index = static::random_int(0, $length - 1); return $arr[$keys[$index]]; }
php
public static function array_pop_rand(array &$arr) { $length = \count($arr); if (! $length) { return false; } // Nothing random about an array with one thing. if (1 === $length) { return static::array_pop_top($arr); } $keys = \array_keys($arr); $index = static::random_int(0, $length - 1); return $arr[$keys[$index]]; }
[ "public", "static", "function", "array_pop_rand", "(", "array", "&", "$", "arr", ")", "{", "$", "length", "=", "\\", "count", "(", "$", "arr", ")", ";", "if", "(", "!", "$", "length", ")", "{", "return", "false", ";", "}", "// Nothing random about an array with one thing.", "if", "(", "1", "===", "$", "length", ")", "{", "return", "static", "::", "array_pop_top", "(", "$", "arr", ")", ";", "}", "$", "keys", "=", "\\", "array_keys", "(", "$", "arr", ")", ";", "$", "index", "=", "static", "::", "random_int", "(", "0", ",", "$", "length", "-", "1", ")", ";", "return", "$", "arr", "[", "$", "keys", "[", "$", "index", "]", "]", ";", "}" ]
Return a random array element. @param array $arr Array. @return mixed Value. False on error.
[ "Return", "a", "random", "array", "element", "." ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L290-L306
29,604
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.array_pop_top
public static function array_pop_top(array &$arr) { if (! \count($arr)) { return false; } \reset($arr); return $arr[\key($arr)]; }
php
public static function array_pop_top(array &$arr) { if (! \count($arr)) { return false; } \reset($arr); return $arr[\key($arr)]; }
[ "public", "static", "function", "array_pop_top", "(", "array", "&", "$", "arr", ")", "{", "if", "(", "!", "\\", "count", "(", "$", "arr", ")", ")", "{", "return", "false", ";", "}", "\\", "reset", "(", "$", "arr", ")", ";", "return", "$", "arr", "[", "\\", "key", "(", "$", "arr", ")", "]", ";", "}" ]
Return the first value of an array. @param array $arr Array. @return mixed Value. False on error.
[ "Return", "the", "first", "value", "of", "an", "array", "." ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L314-L321
29,605
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.cc_exp_months
public static function cc_exp_months(string $format='m - M') { $months = array(); for ($x = 1; $x <= 12; ++$x) { $months[$x] = \date($format, \strtotime('2000-' . \sprintf('%02d', $x) . '-01')); } return $months; }
php
public static function cc_exp_months(string $format='m - M') { $months = array(); for ($x = 1; $x <= 12; ++$x) { $months[$x] = \date($format, \strtotime('2000-' . \sprintf('%02d', $x) . '-01')); } return $months; }
[ "public", "static", "function", "cc_exp_months", "(", "string", "$", "format", "=", "'m - M'", ")", "{", "$", "months", "=", "array", "(", ")", ";", "for", "(", "$", "x", "=", "1", ";", "$", "x", "<=", "12", ";", "++", "$", "x", ")", "{", "$", "months", "[", "$", "x", "]", "=", "\\", "date", "(", "$", "format", ",", "\\", "strtotime", "(", "'2000-'", ".", "\\", "sprintf", "(", "'%02d'", ",", "$", "x", ")", ".", "'-01'", ")", ")", ";", "}", "return", "$", "months", ";", "}" ]
Generate Credit Card Expiration Months @param string $format Date format. @return array Months.
[ "Generate", "Credit", "Card", "Expiration", "Months" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L329-L335
29,606
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.cc_exp_years
public static function cc_exp_years(int $length=10) { if ($length < 1) { $length = 10; } $years = array(); for ($x = 0; $x < $length; ++$x) { $year = (int) (\date('Y') + $x); $years[$year] = $year; } return $years; }
php
public static function cc_exp_years(int $length=10) { if ($length < 1) { $length = 10; } $years = array(); for ($x = 0; $x < $length; ++$x) { $year = (int) (\date('Y') + $x); $years[$year] = $year; } return $years; }
[ "public", "static", "function", "cc_exp_years", "(", "int", "$", "length", "=", "10", ")", "{", "if", "(", "$", "length", "<", "1", ")", "{", "$", "length", "=", "10", ";", "}", "$", "years", "=", "array", "(", ")", ";", "for", "(", "$", "x", "=", "0", ";", "$", "x", "<", "$", "length", ";", "++", "$", "x", ")", "{", "$", "year", "=", "(", "int", ")", "(", "\\", "date", "(", "'Y'", ")", "+", "$", "x", ")", ";", "$", "years", "[", "$", "year", "]", "=", "$", "year", ";", "}", "return", "$", "years", ";", "}" ]
Generate Credit Card Expiration Years @param int $length Number of years. @return array Years.
[ "Generate", "Credit", "Card", "Expiration", "Years" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L343-L355
29,607
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.datediff
public static function datediff($date1, $date2) { ref\sanitize::date($date1); ref\sanitize::date($date2); // Same or bad dates. if ( ! \is_string($date1) || ! \is_string($date2) || ($date1 === $date2) || ('0000-00-00' === $date1) || ('0000-00-00' === $date2) ) { return 0; } // Prefer DateTime. if (\class_exists('DateTime')) { $date1 = new \DateTime($date1); $date2 = new \DateTime($date2); $diff = $date1->diff($date2); return \abs($diff->days); } // Fallback to counting seconds. $date1 = \strtotime($date1); $date2 = \strtotime($date2); return \ceil(\abs($date2 - $date1) / 60 / 60 / 24); }
php
public static function datediff($date1, $date2) { ref\sanitize::date($date1); ref\sanitize::date($date2); // Same or bad dates. if ( ! \is_string($date1) || ! \is_string($date2) || ($date1 === $date2) || ('0000-00-00' === $date1) || ('0000-00-00' === $date2) ) { return 0; } // Prefer DateTime. if (\class_exists('DateTime')) { $date1 = new \DateTime($date1); $date2 = new \DateTime($date2); $diff = $date1->diff($date2); return \abs($diff->days); } // Fallback to counting seconds. $date1 = \strtotime($date1); $date2 = \strtotime($date2); return \ceil(\abs($date2 - $date1) / 60 / 60 / 24); }
[ "public", "static", "function", "datediff", "(", "$", "date1", ",", "$", "date2", ")", "{", "ref", "\\", "sanitize", "::", "date", "(", "$", "date1", ")", ";", "ref", "\\", "sanitize", "::", "date", "(", "$", "date2", ")", ";", "// Same or bad dates.", "if", "(", "!", "\\", "is_string", "(", "$", "date1", ")", "||", "!", "\\", "is_string", "(", "$", "date2", ")", "||", "(", "$", "date1", "===", "$", "date2", ")", "||", "(", "'0000-00-00'", "===", "$", "date1", ")", "||", "(", "'0000-00-00'", "===", "$", "date2", ")", ")", "{", "return", "0", ";", "}", "// Prefer DateTime.", "if", "(", "\\", "class_exists", "(", "'DateTime'", ")", ")", "{", "$", "date1", "=", "new", "\\", "DateTime", "(", "$", "date1", ")", ";", "$", "date2", "=", "new", "\\", "DateTime", "(", "$", "date2", ")", ";", "$", "diff", "=", "$", "date1", "->", "diff", "(", "$", "date2", ")", ";", "return", "\\", "abs", "(", "$", "diff", "->", "days", ")", ";", "}", "// Fallback to counting seconds.", "$", "date1", "=", "\\", "strtotime", "(", "$", "date1", ")", ";", "$", "date2", "=", "\\", "strtotime", "(", "$", "date2", ")", ";", "return", "\\", "ceil", "(", "\\", "abs", "(", "$", "date2", "-", "$", "date1", ")", "/", "60", "/", "60", "/", "24", ")", ";", "}" ]
Days Between Dates @param string $date1 Date. @param string $date2 Date. @return int Difference in Days.
[ "Days", "Between", "Dates" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L364-L392
29,608
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.in_range
public static function in_range($value, $min=null, $max=null) { return sanitize::to_range($value, $min, $max) === $value; }
php
public static function in_range($value, $min=null, $max=null) { return sanitize::to_range($value, $min, $max) === $value; }
[ "public", "static", "function", "in_range", "(", "$", "value", ",", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "return", "sanitize", "::", "to_range", "(", "$", "value", ",", "$", "min", ",", "$", "max", ")", "===", "$", "value", ";", "}" ]
Is Value In Range? @param mixed $value Value. @param mixed $min Min. @param mixed $max Max. @return bool True/false.
[ "Is", "Value", "In", "Range?" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L414-L416
29,609
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.ip_in_range
public static function ip_in_range(string $ip, $min, $max=null) { ref\sanitize::ip($ip, true); if (! \is_string($min)) { return false; } // Bad IP. if (! $ip) { return false; } // Is $min a range? if (false !== \strpos($min, '/')) { if (false === ($range = format::cidr_to_range($min))) { return false; } $min = $range['min']; $max = $range['max']; } // Max is required otherwise. elseif (null === $max) { return false; } // Convert everything to a number. ref\format::ip_to_number($ip); ref\format::ip_to_number($min); ref\format::ip_to_number($max); if ( (false !== $ip) && (false !== $min) && (false !== $max) ) { return static::in_range($ip, $min, $max); } return false; }
php
public static function ip_in_range(string $ip, $min, $max=null) { ref\sanitize::ip($ip, true); if (! \is_string($min)) { return false; } // Bad IP. if (! $ip) { return false; } // Is $min a range? if (false !== \strpos($min, '/')) { if (false === ($range = format::cidr_to_range($min))) { return false; } $min = $range['min']; $max = $range['max']; } // Max is required otherwise. elseif (null === $max) { return false; } // Convert everything to a number. ref\format::ip_to_number($ip); ref\format::ip_to_number($min); ref\format::ip_to_number($max); if ( (false !== $ip) && (false !== $min) && (false !== $max) ) { return static::in_range($ip, $min, $max); } return false; }
[ "public", "static", "function", "ip_in_range", "(", "string", "$", "ip", ",", "$", "min", ",", "$", "max", "=", "null", ")", "{", "ref", "\\", "sanitize", "::", "ip", "(", "$", "ip", ",", "true", ")", ";", "if", "(", "!", "\\", "is_string", "(", "$", "min", ")", ")", "{", "return", "false", ";", "}", "// Bad IP.", "if", "(", "!", "$", "ip", ")", "{", "return", "false", ";", "}", "// Is $min a range?", "if", "(", "false", "!==", "\\", "strpos", "(", "$", "min", ",", "'/'", ")", ")", "{", "if", "(", "false", "===", "(", "$", "range", "=", "format", "::", "cidr_to_range", "(", "$", "min", ")", ")", ")", "{", "return", "false", ";", "}", "$", "min", "=", "$", "range", "[", "'min'", "]", ";", "$", "max", "=", "$", "range", "[", "'max'", "]", ";", "}", "// Max is required otherwise.", "elseif", "(", "null", "===", "$", "max", ")", "{", "return", "false", ";", "}", "// Convert everything to a number.", "ref", "\\", "format", "::", "ip_to_number", "(", "$", "ip", ")", ";", "ref", "\\", "format", "::", "ip_to_number", "(", "$", "min", ")", ";", "ref", "\\", "format", "::", "ip_to_number", "(", "$", "max", ")", ";", "if", "(", "(", "false", "!==", "$", "ip", ")", "&&", "(", "false", "!==", "$", "min", ")", "&&", "(", "false", "!==", "$", "max", ")", ")", "{", "return", "static", "::", "in_range", "(", "$", "ip", ",", "$", "min", ",", "$", "max", ")", ";", "}", "return", "false", ";", "}" ]
IP in Range? Check to see if an IP is in range. This either accepts a minimum and maximum IP, or a CIDR. @param string $ip String. @param string $min Min or CIDR. @param string $max Max. @return bool True/false.
[ "IP", "in", "Range?" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L430-L468
29,610
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.is_utf8
public static function is_utf8($str) { if (\is_numeric($str) || \is_bool($str)) { return true; } elseif (\is_string($str)) { return (bool) \preg_match('//u', $str); } return false; }
php
public static function is_utf8($str) { if (\is_numeric($str) || \is_bool($str)) { return true; } elseif (\is_string($str)) { return (bool) \preg_match('//u', $str); } return false; }
[ "public", "static", "function", "is_utf8", "(", "$", "str", ")", "{", "if", "(", "\\", "is_numeric", "(", "$", "str", ")", "||", "\\", "is_bool", "(", "$", "str", ")", ")", "{", "return", "true", ";", "}", "elseif", "(", "\\", "is_string", "(", "$", "str", ")", ")", "{", "return", "(", "bool", ")", "\\", "preg_match", "(", "'//u'", ",", "$", "str", ")", ";", "}", "return", "false", ";", "}" ]
Is Value Valid UTF-8? @param string $str String. @return bool True/false.
[ "Is", "Value", "Valid", "UTF", "-", "8?" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L496-L505
29,611
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.json_decode_array
public static function json_decode_array($json, $defaults=null, bool $strict=true, bool $recursive=true) { ref\format::json_decode($json); if ((null === $json) || (\is_string($json) && ! $json)) { $json = array(); } else { ref\cast::array($json); } if (\is_array($defaults)) { return static::parse_args($json, $defaults, $strict, $recursive); } else { return $json; } }
php
public static function json_decode_array($json, $defaults=null, bool $strict=true, bool $recursive=true) { ref\format::json_decode($json); if ((null === $json) || (\is_string($json) && ! $json)) { $json = array(); } else { ref\cast::array($json); } if (\is_array($defaults)) { return static::parse_args($json, $defaults, $strict, $recursive); } else { return $json; } }
[ "public", "static", "function", "json_decode_array", "(", "$", "json", ",", "$", "defaults", "=", "null", ",", "bool", "$", "strict", "=", "true", ",", "bool", "$", "recursive", "=", "true", ")", "{", "ref", "\\", "format", "::", "json_decode", "(", "$", "json", ")", ";", "if", "(", "(", "null", "===", "$", "json", ")", "||", "(", "\\", "is_string", "(", "$", "json", ")", "&&", "!", "$", "json", ")", ")", "{", "$", "json", "=", "array", "(", ")", ";", "}", "else", "{", "ref", "\\", "cast", "::", "array", "(", "$", "json", ")", ";", "}", "if", "(", "\\", "is_array", "(", "$", "defaults", ")", ")", "{", "return", "static", "::", "parse_args", "(", "$", "json", ",", "$", "defaults", ",", "$", "strict", ",", "$", "recursive", ")", ";", "}", "else", "{", "return", "$", "json", ";", "}", "}" ]
JSON Decode As Array This ensures a JSON string is always decoded to an array, optionally matching the structure of a template object. @param string $json JSON. @param mixed $defaults Template. @param bool $strict Enforce types if templating. @param bool $recursive Recursive templating. @return array Data.
[ "JSON", "Decode", "As", "Array" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L520-L536
29,612
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.length_in_range
public static function length_in_range(string $str, $min=null, $max=null) { if ((null !== $min) && ! \is_int($min)) { ref\cast::int($min, true); } if ((null !== $max) && ! \is_int($max)) { ref\cast::int($max, true); } $length = mb::strlen($str); if ((null !== $min) && (null !== $max) && $min > $max) { static::switcheroo($min, $max); } if ((null !== $min) && $min > $length) { return false; } if ((null !== $max) && $max < $length) { return false; } return true; }
php
public static function length_in_range(string $str, $min=null, $max=null) { if ((null !== $min) && ! \is_int($min)) { ref\cast::int($min, true); } if ((null !== $max) && ! \is_int($max)) { ref\cast::int($max, true); } $length = mb::strlen($str); if ((null !== $min) && (null !== $max) && $min > $max) { static::switcheroo($min, $max); } if ((null !== $min) && $min > $length) { return false; } if ((null !== $max) && $max < $length) { return false; } return true; }
[ "public", "static", "function", "length_in_range", "(", "string", "$", "str", ",", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "if", "(", "(", "null", "!==", "$", "min", ")", "&&", "!", "\\", "is_int", "(", "$", "min", ")", ")", "{", "ref", "\\", "cast", "::", "int", "(", "$", "min", ",", "true", ")", ";", "}", "if", "(", "(", "null", "!==", "$", "max", ")", "&&", "!", "\\", "is_int", "(", "$", "max", ")", ")", "{", "ref", "\\", "cast", "::", "int", "(", "$", "max", ",", "true", ")", ";", "}", "$", "length", "=", "mb", "::", "strlen", "(", "$", "str", ")", ";", "if", "(", "(", "null", "!==", "$", "min", ")", "&&", "(", "null", "!==", "$", "max", ")", "&&", "$", "min", ">", "$", "max", ")", "{", "static", "::", "switcheroo", "(", "$", "min", ",", "$", "max", ")", ";", "}", "if", "(", "(", "null", "!==", "$", "min", ")", "&&", "$", "min", ">", "$", "length", ")", "{", "return", "false", ";", "}", "if", "(", "(", "null", "!==", "$", "max", ")", "&&", "$", "max", "<", "$", "length", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Length in Range See if the length of a string is between two extremes. @param string $str String. @param int $min Min length. @param int $max Max length. @return bool True/false.
[ "Length", "in", "Range" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L548-L570
29,613
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.random_int
public static function random_int(int $min=0, int $max=1) { if ($min > $max) { static::switcheroo($min, $max); } return \random_int($min, $max); }
php
public static function random_int(int $min=0, int $max=1) { if ($min > $max) { static::switcheroo($min, $max); } return \random_int($min, $max); }
[ "public", "static", "function", "random_int", "(", "int", "$", "min", "=", "0", ",", "int", "$", "max", "=", "1", ")", "{", "if", "(", "$", "min", ">", "$", "max", ")", "{", "static", "::", "switcheroo", "(", "$", "min", ",", "$", "max", ")", ";", "}", "return", "\\", "random_int", "(", "$", "min", ",", "$", "max", ")", ";", "}" ]
Generate Random Integer This will use the most secure function available for the environment. @param int $min Min. @param int $max Max. @return int Random number.
[ "Generate", "Random", "Integer" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L629-L635
29,614
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.random_string
public static function random_string(int $length=10, $soup=null) { if ($length < 1) { return ''; } if (\is_array($soup) && \count($soup)) { ref\cast::string($soup); $soup = \implode('', $soup); ref\sanitize::printable($soup); $soup = \preg_replace('/\s/u', '', $soup); $soup = \array_unique(mb::str_split($soup, 1, true)); $soup = \array_values($soup); if (! \count($soup)) { return ''; } } // Use default soup. if (! \is_array($soup) || ! \count($soup)) { $soup = constants::RANDOM_CHARS; } // Pick nine entries at random. $salt = ''; $max = \count($soup) - 1; for ($x = 0; $x < $length; ++$x) { $salt .= $soup[static::random_int(0, $max)]; } return $salt; }
php
public static function random_string(int $length=10, $soup=null) { if ($length < 1) { return ''; } if (\is_array($soup) && \count($soup)) { ref\cast::string($soup); $soup = \implode('', $soup); ref\sanitize::printable($soup); $soup = \preg_replace('/\s/u', '', $soup); $soup = \array_unique(mb::str_split($soup, 1, true)); $soup = \array_values($soup); if (! \count($soup)) { return ''; } } // Use default soup. if (! \is_array($soup) || ! \count($soup)) { $soup = constants::RANDOM_CHARS; } // Pick nine entries at random. $salt = ''; $max = \count($soup) - 1; for ($x = 0; $x < $length; ++$x) { $salt .= $soup[static::random_int(0, $max)]; } return $salt; }
[ "public", "static", "function", "random_string", "(", "int", "$", "length", "=", "10", ",", "$", "soup", "=", "null", ")", "{", "if", "(", "$", "length", "<", "1", ")", "{", "return", "''", ";", "}", "if", "(", "\\", "is_array", "(", "$", "soup", ")", "&&", "\\", "count", "(", "$", "soup", ")", ")", "{", "ref", "\\", "cast", "::", "string", "(", "$", "soup", ")", ";", "$", "soup", "=", "\\", "implode", "(", "''", ",", "$", "soup", ")", ";", "ref", "\\", "sanitize", "::", "printable", "(", "$", "soup", ")", ";", "$", "soup", "=", "\\", "preg_replace", "(", "'/\\s/u'", ",", "''", ",", "$", "soup", ")", ";", "$", "soup", "=", "\\", "array_unique", "(", "mb", "::", "str_split", "(", "$", "soup", ",", "1", ",", "true", ")", ")", ";", "$", "soup", "=", "\\", "array_values", "(", "$", "soup", ")", ";", "if", "(", "!", "\\", "count", "(", "$", "soup", ")", ")", "{", "return", "''", ";", "}", "}", "// Use default soup.", "if", "(", "!", "\\", "is_array", "(", "$", "soup", ")", "||", "!", "\\", "count", "(", "$", "soup", ")", ")", "{", "$", "soup", "=", "constants", "::", "RANDOM_CHARS", ";", "}", "// Pick nine entries at random.", "$", "salt", "=", "''", ";", "$", "max", "=", "\\", "count", "(", "$", "soup", ")", "-", "1", ";", "for", "(", "$", "x", "=", "0", ";", "$", "x", "<", "$", "length", ";", "++", "$", "x", ")", "{", "$", "salt", ".=", "$", "soup", "[", "static", "::", "random_int", "(", "0", ",", "$", "max", ")", "]", ";", "}", "return", "$", "salt", ";", "}" ]
Generate Random String By default the string will only contain unambiguous uppercase letters and numbers. Alternate alphabets can be passed instead. @param int $length Length. @param array $soup Alternate alphabet. @return string Random string.
[ "Generate", "Random", "String" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L648-L680
29,615
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.switcheroo
public static function switcheroo(&$var1, &$var2) { $tmp = $var1; $var1 = $var2; $var2 = $tmp; return true; }
php
public static function switcheroo(&$var1, &$var2) { $tmp = $var1; $var1 = $var2; $var2 = $tmp; return true; }
[ "public", "static", "function", "switcheroo", "(", "&", "$", "var1", ",", "&", "$", "var2", ")", "{", "$", "tmp", "=", "$", "var1", ";", "$", "var1", "=", "$", "var2", ";", "$", "var2", "=", "$", "tmp", ";", "return", "true", ";", "}" ]
Switch Two Variables @param mixed $var1 Variable. @param mixed $var2 Variable. @return bool True.
[ "Switch", "Two", "Variables" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L689-L695
29,616
Blobfolio/blob-common
lib/blobfolio/common/data.php
data.unsetcookie
public static function unsetcookie(string $name, string $path='', string $domain='', bool $secure=false, bool $httponly=false) { if (! \headers_sent()) { \setcookie($name, false, -1, $path, $domain, $secure, $httponly); if (isset($_COOKIE[$name])) { unset($_COOKIE[$name]); } return true; } return false; }
php
public static function unsetcookie(string $name, string $path='', string $domain='', bool $secure=false, bool $httponly=false) { if (! \headers_sent()) { \setcookie($name, false, -1, $path, $domain, $secure, $httponly); if (isset($_COOKIE[$name])) { unset($_COOKIE[$name]); } return true; } return false; }
[ "public", "static", "function", "unsetcookie", "(", "string", "$", "name", ",", "string", "$", "path", "=", "''", ",", "string", "$", "domain", "=", "''", ",", "bool", "$", "secure", "=", "false", ",", "bool", "$", "httponly", "=", "false", ")", "{", "if", "(", "!", "\\", "headers_sent", "(", ")", ")", "{", "\\", "setcookie", "(", "$", "name", ",", "false", ",", "-", "1", ",", "$", "path", ",", "$", "domain", ",", "$", "secure", ",", "$", "httponly", ")", ";", "if", "(", "isset", "(", "$", "_COOKIE", "[", "$", "name", "]", ")", ")", "{", "unset", "(", "$", "_COOKIE", "[", "$", "name", "]", ")", ";", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
Delete a Cookie A companion to PHP's `setcookie()` function. It attempts to remove the cookie. The same path, etc., values should be passed as were used to first set it. @param string $name Name. @param string $path Path. @param string $domain Domain. @param bool $secure SSL only. @param bool $httponly HTTP only. @return bool True/false.
[ "Delete", "a", "Cookie" ]
7b43d5526cc9d09853771d950b2956e98e680db1
https://github.com/Blobfolio/blob-common/blob/7b43d5526cc9d09853771d950b2956e98e680db1/lib/blobfolio/common/data.php#L711-L723
29,617
polyfony-inc/polyfony
Private/Polyfony/Uploader.php
Uploader.source
public function source($path, $override_chroot = true) { // if chroot is enabled, restrict the path to the chroot $this->Source = Filesystem::chroot($path, $override_chroot); // return self return($this); }
php
public function source($path, $override_chroot = true) { // if chroot is enabled, restrict the path to the chroot $this->Source = Filesystem::chroot($path, $override_chroot); // return self return($this); }
[ "public", "function", "source", "(", "$", "path", ",", "$", "override_chroot", "=", "true", ")", "{", "// if chroot is enabled, restrict the path to the chroot", "$", "this", "->", "Source", "=", "Filesystem", "::", "chroot", "(", "$", "path", ",", "$", "override_chroot", ")", ";", "// return self", "return", "(", "$", "this", ")", ";", "}" ]
set the source file path, disable chroot before of the tmp folder
[ "set", "the", "source", "file", "path", "disable", "chroot", "before", "of", "the", "tmp", "folder" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Uploader.php#L42-L47
29,618
polyfony-inc/polyfony
Private/Polyfony/Uploader.php
Uploader.destination
public function destination($path, $override_chroot = false) { // set the path $this->Destination = Filesystem::chroot($path, $override_chroot); // return self return($this); }
php
public function destination($path, $override_chroot = false) { // set the path $this->Destination = Filesystem::chroot($path, $override_chroot); // return self return($this); }
[ "public", "function", "destination", "(", "$", "path", ",", "$", "override_chroot", "=", "false", ")", "{", "// set the path", "$", "this", "->", "Destination", "=", "Filesystem", "::", "chroot", "(", "$", "path", ",", "$", "override_chroot", ")", ";", "// return self", "return", "(", "$", "this", ")", ";", "}" ]
set the destination
[ "set", "the", "destination" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Uploader.php#L50-L55
29,619
polyfony-inc/polyfony
Private/Polyfony/Uploader.php
Uploader.limitTypes
public function limitTypes($allowed) { // if allowed is an array if(is_array($allowed)) { // push the whole table $this->Limits->Types = $allowed; } // allowed is a string else { // push it $this->Limits->Types[] = $allowed; } // return self return($this); }
php
public function limitTypes($allowed) { // if allowed is an array if(is_array($allowed)) { // push the whole table $this->Limits->Types = $allowed; } // allowed is a string else { // push it $this->Limits->Types[] = $allowed; } // return self return($this); }
[ "public", "function", "limitTypes", "(", "$", "allowed", ")", "{", "// if allowed is an array", "if", "(", "is_array", "(", "$", "allowed", ")", ")", "{", "// push the whole table", "$", "this", "->", "Limits", "->", "Types", "=", "$", "allowed", ";", "}", "// allowed is a string", "else", "{", "// push it", "$", "this", "->", "Limits", "->", "Types", "[", "]", "=", "$", "allowed", ";", "}", "// return self", "return", "(", "$", "this", ")", ";", "}" ]
limit types to array or mimetypes
[ "limit", "types", "to", "array", "or", "mimetypes" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Uploader.php#L69-L82
29,620
hnhdigital-os/laravel-model-schema
src/Model.php
Model.schemaCache
private static function schemaCache(...$args) { if (count($args) == 1) { $key = array_pop($args); if (isset(static::$schema_cache[$key])) { return static::$schema_cache[$key]; } return false; } list($key, $value) = $args; static::$schema_cache[$key] = $value; }
php
private static function schemaCache(...$args) { if (count($args) == 1) { $key = array_pop($args); if (isset(static::$schema_cache[$key])) { return static::$schema_cache[$key]; } return false; } list($key, $value) = $args; static::$schema_cache[$key] = $value; }
[ "private", "static", "function", "schemaCache", "(", "...", "$", "args", ")", "{", "if", "(", "count", "(", "$", "args", ")", "==", "1", ")", "{", "$", "key", "=", "array_pop", "(", "$", "args", ")", ";", "if", "(", "isset", "(", "static", "::", "$", "schema_cache", "[", "$", "key", "]", ")", ")", "{", "return", "static", "::", "$", "schema_cache", "[", "$", "key", "]", ";", "}", "return", "false", ";", "}", "list", "(", "$", "key", ",", "$", "value", ")", "=", "$", "args", ";", "static", "::", "$", "schema_cache", "[", "$", "key", "]", "=", "$", "value", ";", "}" ]
Set or get Cache for this key. @param string $key @param array $data @return void
[ "Set", "or", "get", "Cache", "for", "this", "key", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Model.php#L174-L188
29,621
hnhdigital-os/laravel-model-schema
src/Model.php
Model.getSchemaCache
private function getSchemaCache($key) { if (isset($this->model_schema_cache[$key])) { return $this->model_schema_cache[$key]; } return false; }
php
private function getSchemaCache($key) { if (isset($this->model_schema_cache[$key])) { return $this->model_schema_cache[$key]; } return false; }
[ "private", "function", "getSchemaCache", "(", "$", "key", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "model_schema_cache", "[", "$", "key", "]", ")", ")", "{", "return", "$", "this", "->", "model_schema_cache", "[", "$", "key", "]", ";", "}", "return", "false", ";", "}" ]
Get cache for this key. @param string $key @return void
[ "Get", "cache", "for", "this", "key", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Model.php#L270-L277
29,622
hnhdigital-os/laravel-model-schema
src/Model.php
Model.setSchema
public function setSchema($entry, $keys, $value, $reset = false, $reset_value = null) { // Reset existing values in the schema. if ($reset) { $current = $this->getSchema($entry); foreach ($current as $key => $value) { if (is_null($reset_value)) { unset($this->schema[$key][$entry]); continue; } array_set($this->model_schema, $key.'.'.$entry, $reset_value); } } // Keys can be a single string attribute. if (!is_array($keys)) { $keys = [$keys]; } // Update each of the keys. foreach ($keys as $key) { array_set($this->model_schema, $key.'.'.$entry, $value); } // Break the cache. $this->breakSchemaCache($entry.'_0'); $this->breakSchemaCache($entry.'_1'); return $this; }
php
public function setSchema($entry, $keys, $value, $reset = false, $reset_value = null) { // Reset existing values in the schema. if ($reset) { $current = $this->getSchema($entry); foreach ($current as $key => $value) { if (is_null($reset_value)) { unset($this->schema[$key][$entry]); continue; } array_set($this->model_schema, $key.'.'.$entry, $reset_value); } } // Keys can be a single string attribute. if (!is_array($keys)) { $keys = [$keys]; } // Update each of the keys. foreach ($keys as $key) { array_set($this->model_schema, $key.'.'.$entry, $value); } // Break the cache. $this->breakSchemaCache($entry.'_0'); $this->breakSchemaCache($entry.'_1'); return $this; }
[ "public", "function", "setSchema", "(", "$", "entry", ",", "$", "keys", ",", "$", "value", ",", "$", "reset", "=", "false", ",", "$", "reset_value", "=", "null", ")", "{", "// Reset existing values in the schema.", "if", "(", "$", "reset", ")", "{", "$", "current", "=", "$", "this", "->", "getSchema", "(", "$", "entry", ")", ";", "foreach", "(", "$", "current", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_null", "(", "$", "reset_value", ")", ")", "{", "unset", "(", "$", "this", "->", "schema", "[", "$", "key", "]", "[", "$", "entry", "]", ")", ";", "continue", ";", "}", "array_set", "(", "$", "this", "->", "model_schema", ",", "$", "key", ".", "'.'", ".", "$", "entry", ",", "$", "reset_value", ")", ";", "}", "}", "// Keys can be a single string attribute.", "if", "(", "!", "is_array", "(", "$", "keys", ")", ")", "{", "$", "keys", "=", "[", "$", "keys", "]", ";", "}", "// Update each of the keys.", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "array_set", "(", "$", "this", "->", "model_schema", ",", "$", "key", ".", "'.'", ".", "$", "entry", ",", "$", "value", ")", ";", "}", "// Break the cache.", "$", "this", "->", "breakSchemaCache", "(", "$", "entry", ".", "'_0'", ")", ";", "$", "this", "->", "breakSchemaCache", "(", "$", "entry", ".", "'_1'", ")", ";", "return", "$", "this", ";", "}" ]
Set an entry within the schema. @param string $entry @param string|array $keys @param bool $reset @param mixed $reset_value @return array
[ "Set", "an", "entry", "within", "the", "schema", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Model.php#L301-L331
29,623
hnhdigital-os/laravel-model-schema
src/Model.php
Model.cache
protected function cache($key, $value) { if (array_has($this->model_cache, $key)) { return array_get($this->model_cache, $key); } if (is_callable($value)) { $result = $value(); } else { $result = $value; } array_set($this->model_cache, $key, $result); return $result; }
php
protected function cache($key, $value) { if (array_has($this->model_cache, $key)) { return array_get($this->model_cache, $key); } if (is_callable($value)) { $result = $value(); } else { $result = $value; } array_set($this->model_cache, $key, $result); return $result; }
[ "protected", "function", "cache", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "array_has", "(", "$", "this", "->", "model_cache", ",", "$", "key", ")", ")", "{", "return", "array_get", "(", "$", "this", "->", "model_cache", ",", "$", "key", ")", ";", "}", "if", "(", "is_callable", "(", "$", "value", ")", ")", "{", "$", "result", "=", "$", "value", "(", ")", ";", "}", "else", "{", "$", "result", "=", "$", "value", ";", "}", "array_set", "(", "$", "this", "->", "model_cache", ",", "$", "key", ",", "$", "result", ")", ";", "return", "$", "result", ";", "}" ]
Cache this value. @param string $key @param mixed $value @return mixed
[ "Cache", "this", "value", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Model.php#L357-L372
29,624
hnhdigital-os/laravel-model-schema
src/Model.php
Model.boot
protected static function boot() { parent::boot(); // Boot event for creating this model. // Set default values if specified. // Validate dirty attributes before commiting to save. static::creating(function ($model) { $model->setDefaultValuesForAttributes(); if (!$model->savingValidation()) { $validator = $model->getValidator(); $issues = $validator->errors()->all(); $message = sprintf( "Validation failed on creating %s.\n%s", $model->getTable(), implode("\n", $issues) ); throw new Exceptions\ValidationException($message, 0, null, $validator); } }); // Boot event once model has been created. // Add missing attributes using the schema. static::created(function ($model) { $model->addMissingAttributes(); }); // Boot event for updating this model. // Validate dirty attributes before commiting to save. static::updating(function ($model) { if (!$model->savingValidation()) { $validator = $model->getValidator(); $issues = $validator->errors()->all(); $message = sprintf( "Validation failed on saving %s (%s).\n%s", $model->getTable(), $model->getKey(), implode("\n", $issues) ); throw new Exceptions\ValidationException($message, 0, null, $validator); } }); }
php
protected static function boot() { parent::boot(); // Boot event for creating this model. // Set default values if specified. // Validate dirty attributes before commiting to save. static::creating(function ($model) { $model->setDefaultValuesForAttributes(); if (!$model->savingValidation()) { $validator = $model->getValidator(); $issues = $validator->errors()->all(); $message = sprintf( "Validation failed on creating %s.\n%s", $model->getTable(), implode("\n", $issues) ); throw new Exceptions\ValidationException($message, 0, null, $validator); } }); // Boot event once model has been created. // Add missing attributes using the schema. static::created(function ($model) { $model->addMissingAttributes(); }); // Boot event for updating this model. // Validate dirty attributes before commiting to save. static::updating(function ($model) { if (!$model->savingValidation()) { $validator = $model->getValidator(); $issues = $validator->errors()->all(); $message = sprintf( "Validation failed on saving %s (%s).\n%s", $model->getTable(), $model->getKey(), implode("\n", $issues) ); throw new Exceptions\ValidationException($message, 0, null, $validator); } }); }
[ "protected", "static", "function", "boot", "(", ")", "{", "parent", "::", "boot", "(", ")", ";", "// Boot event for creating this model.", "// Set default values if specified.", "// Validate dirty attributes before commiting to save.", "static", "::", "creating", "(", "function", "(", "$", "model", ")", "{", "$", "model", "->", "setDefaultValuesForAttributes", "(", ")", ";", "if", "(", "!", "$", "model", "->", "savingValidation", "(", ")", ")", "{", "$", "validator", "=", "$", "model", "->", "getValidator", "(", ")", ";", "$", "issues", "=", "$", "validator", "->", "errors", "(", ")", "->", "all", "(", ")", ";", "$", "message", "=", "sprintf", "(", "\"Validation failed on creating %s.\\n%s\"", ",", "$", "model", "->", "getTable", "(", ")", ",", "implode", "(", "\"\\n\"", ",", "$", "issues", ")", ")", ";", "throw", "new", "Exceptions", "\\", "ValidationException", "(", "$", "message", ",", "0", ",", "null", ",", "$", "validator", ")", ";", "}", "}", ")", ";", "// Boot event once model has been created.", "// Add missing attributes using the schema.", "static", "::", "created", "(", "function", "(", "$", "model", ")", "{", "$", "model", "->", "addMissingAttributes", "(", ")", ";", "}", ")", ";", "// Boot event for updating this model.", "// Validate dirty attributes before commiting to save.", "static", "::", "updating", "(", "function", "(", "$", "model", ")", "{", "if", "(", "!", "$", "model", "->", "savingValidation", "(", ")", ")", "{", "$", "validator", "=", "$", "model", "->", "getValidator", "(", ")", ";", "$", "issues", "=", "$", "validator", "->", "errors", "(", ")", "->", "all", "(", ")", ";", "$", "message", "=", "sprintf", "(", "\"Validation failed on saving %s (%s).\\n%s\"", ",", "$", "model", "->", "getTable", "(", ")", ",", "$", "model", "->", "getKey", "(", ")", ",", "implode", "(", "\"\\n\"", ",", "$", "issues", ")", ")", ";", "throw", "new", "Exceptions", "\\", "ValidationException", "(", "$", "message", ",", "0", ",", "null", ",", "$", "validator", ")", ";", "}", "}", ")", ";", "}" ]
Boot events. @return void
[ "Boot", "events", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Model.php#L379-L425
29,625
secucard/secucard-connect-php-sdk
src/SecucardConnect/Auth/OauthProvider.php
OauthProvider.appyAuthorization
public function appyAuthorization(RequestInterface $request, array $options = null) { // Only sign requests using "auth"="oauth" // IMPORTANT: you have to create special auth client (GuzzleHttp\Client) if you want to get all the request authorized if (!isset($options['auth']) || $options['auth'] != 'oauth') { return $request; } // get Access token for current request $accessToken = $this->getAccessToken(); if (is_string($accessToken)) { return $request->withHeader('Authorization', 'Bearer ' . $accessToken); } else { throw new ClientError('Authentication error, invalid on no access token data returned.'); } }
php
public function appyAuthorization(RequestInterface $request, array $options = null) { // Only sign requests using "auth"="oauth" // IMPORTANT: you have to create special auth client (GuzzleHttp\Client) if you want to get all the request authorized if (!isset($options['auth']) || $options['auth'] != 'oauth') { return $request; } // get Access token for current request $accessToken = $this->getAccessToken(); if (is_string($accessToken)) { return $request->withHeader('Authorization', 'Bearer ' . $accessToken); } else { throw new ClientError('Authentication error, invalid on no access token data returned.'); } }
[ "public", "function", "appyAuthorization", "(", "RequestInterface", "$", "request", ",", "array", "$", "options", "=", "null", ")", "{", "// Only sign requests using \"auth\"=\"oauth\"", "// IMPORTANT: you have to create special auth client (GuzzleHttp\\Client) if you want to get all the request authorized", "if", "(", "!", "isset", "(", "$", "options", "[", "'auth'", "]", ")", "||", "$", "options", "[", "'auth'", "]", "!=", "'oauth'", ")", "{", "return", "$", "request", ";", "}", "// get Access token for current request", "$", "accessToken", "=", "$", "this", "->", "getAccessToken", "(", ")", ";", "if", "(", "is_string", "(", "$", "accessToken", ")", ")", "{", "return", "$", "request", "->", "withHeader", "(", "'Authorization'", ",", "'Bearer '", ".", "$", "accessToken", ")", ";", "}", "else", "{", "throw", "new", "ClientError", "(", "'Authentication error, invalid on no access token data returned.'", ")", ";", "}", "}" ]
Adds the authorization header if an access token was found @param RequestInterface $request @param array $options @return RequestInterface If the access token could not properly set to the request. @throws ClientError @throws ApiError @throws AuthError
[ "Adds", "the", "authorization", "header", "if", "an", "access", "token", "was", "found" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Auth/OauthProvider.php#L105-L120
29,626
secucard/secucard-connect-php-sdk
src/SecucardConnect/Auth/OauthProvider.php
OauthProvider.updateToken
private function updateToken(RefreshTokenCredentials $refreshToken = null, $deviceCode = null) { $tokenData = null; // array of url parameters that will be sent in auth request $params = []; if ($refreshToken == null && !empty($deviceCode)) { $tokenData = $this->pollDeviceAccessToken($deviceCode); if ($tokenData === false) { return false; } } else { $this->setParams($params, $refreshToken == null ? $this->credentials : $refreshToken); try { $response = $this->post($params); $tokenData = MapperUtil::mapResponse($response); } catch (Exception $e) { throw($this->mapError($e, 'Error obtaining access token.')); } } if (empty($tokenData)) { throw new ClientError('Error obtaining access token.'); } // Process the returned data, both expired_in and refresh_token are optional parameters $this->accessToken = ['access_token' => $tokenData->access_token,]; if (isset($tokenData->expires_in)) { $this->accessToken['expires_in'] = time() + $tokenData->expires_in; } // Save access token to storage $this->storage->set('access_token', $this->accessToken); if (isset($tokenData->refresh_token)) { $this->refreshToken = $tokenData->refresh_token; // Save refresh token to storage $this->storage->set('refresh_token', $this->refreshToken); } // never delete existing refresh token return true; }
php
private function updateToken(RefreshTokenCredentials $refreshToken = null, $deviceCode = null) { $tokenData = null; // array of url parameters that will be sent in auth request $params = []; if ($refreshToken == null && !empty($deviceCode)) { $tokenData = $this->pollDeviceAccessToken($deviceCode); if ($tokenData === false) { return false; } } else { $this->setParams($params, $refreshToken == null ? $this->credentials : $refreshToken); try { $response = $this->post($params); $tokenData = MapperUtil::mapResponse($response); } catch (Exception $e) { throw($this->mapError($e, 'Error obtaining access token.')); } } if (empty($tokenData)) { throw new ClientError('Error obtaining access token.'); } // Process the returned data, both expired_in and refresh_token are optional parameters $this->accessToken = ['access_token' => $tokenData->access_token,]; if (isset($tokenData->expires_in)) { $this->accessToken['expires_in'] = time() + $tokenData->expires_in; } // Save access token to storage $this->storage->set('access_token', $this->accessToken); if (isset($tokenData->refresh_token)) { $this->refreshToken = $tokenData->refresh_token; // Save refresh token to storage $this->storage->set('refresh_token', $this->refreshToken); } // never delete existing refresh token return true; }
[ "private", "function", "updateToken", "(", "RefreshTokenCredentials", "$", "refreshToken", "=", "null", ",", "$", "deviceCode", "=", "null", ")", "{", "$", "tokenData", "=", "null", ";", "// array of url parameters that will be sent in auth request", "$", "params", "=", "[", "]", ";", "if", "(", "$", "refreshToken", "==", "null", "&&", "!", "empty", "(", "$", "deviceCode", ")", ")", "{", "$", "tokenData", "=", "$", "this", "->", "pollDeviceAccessToken", "(", "$", "deviceCode", ")", ";", "if", "(", "$", "tokenData", "===", "false", ")", "{", "return", "false", ";", "}", "}", "else", "{", "$", "this", "->", "setParams", "(", "$", "params", ",", "$", "refreshToken", "==", "null", "?", "$", "this", "->", "credentials", ":", "$", "refreshToken", ")", ";", "try", "{", "$", "response", "=", "$", "this", "->", "post", "(", "$", "params", ")", ";", "$", "tokenData", "=", "MapperUtil", "::", "mapResponse", "(", "$", "response", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "(", "$", "this", "->", "mapError", "(", "$", "e", ",", "'Error obtaining access token.'", ")", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "tokenData", ")", ")", "{", "throw", "new", "ClientError", "(", "'Error obtaining access token.'", ")", ";", "}", "// Process the returned data, both expired_in and refresh_token are optional parameters", "$", "this", "->", "accessToken", "=", "[", "'access_token'", "=>", "$", "tokenData", "->", "access_token", ",", "]", ";", "if", "(", "isset", "(", "$", "tokenData", "->", "expires_in", ")", ")", "{", "$", "this", "->", "accessToken", "[", "'expires_in'", "]", "=", "time", "(", ")", "+", "$", "tokenData", "->", "expires_in", ";", "}", "// Save access token to storage", "$", "this", "->", "storage", "->", "set", "(", "'access_token'", ",", "$", "this", "->", "accessToken", ")", ";", "if", "(", "isset", "(", "$", "tokenData", "->", "refresh_token", ")", ")", "{", "$", "this", "->", "refreshToken", "=", "$", "tokenData", "->", "refresh_token", ";", "// Save refresh token to storage", "$", "this", "->", "storage", "->", "set", "(", "'refresh_token'", ",", "$", "this", "->", "refreshToken", ")", ";", "}", "// never delete existing refresh token", "return", "true", ";", "}" ]
Function to update token based on GrantTypeInterface @param RefreshTokenCredentials|null $refreshToken Refresh token to update existing token or null to obtain new token. @param null|string $deviceCode @return bool False on pending auth, true else. @throws ClientError @throws ApiError @throws AuthError @throws Exception
[ "Function", "to", "update", "token", "based", "on", "GrantTypeInterface" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Auth/OauthProvider.php#L201-L244
29,627
secucard/secucard-connect-php-sdk
src/SecucardConnect/Auth/OauthProvider.php
OauthProvider.obtainDeviceVerification
private function obtainDeviceVerification() { if (!$this->credentials instanceof DeviceCredentials) { throw new ClientError('Invalid credentials set up, must be of type ' . DeviceCredentials::class); } $params = []; $this->setParams($params, $this->credentials); // if the guzzle gets response http_status other than 200, it will throw an exception even when there is response available try { $response = $this->post($params); return MapperUtil::mapResponse($response, new AuthCodes(), $this->logger); } catch (ClientException $e) { throw $this->mapError($e, 'Error requesting device codes.'); } }
php
private function obtainDeviceVerification() { if (!$this->credentials instanceof DeviceCredentials) { throw new ClientError('Invalid credentials set up, must be of type ' . DeviceCredentials::class); } $params = []; $this->setParams($params, $this->credentials); // if the guzzle gets response http_status other than 200, it will throw an exception even when there is response available try { $response = $this->post($params); return MapperUtil::mapResponse($response, new AuthCodes(), $this->logger); } catch (ClientException $e) { throw $this->mapError($e, 'Error requesting device codes.'); } }
[ "private", "function", "obtainDeviceVerification", "(", ")", "{", "if", "(", "!", "$", "this", "->", "credentials", "instanceof", "DeviceCredentials", ")", "{", "throw", "new", "ClientError", "(", "'Invalid credentials set up, must be of type '", ".", "DeviceCredentials", "::", "class", ")", ";", "}", "$", "params", "=", "[", "]", ";", "$", "this", "->", "setParams", "(", "$", "params", ",", "$", "this", "->", "credentials", ")", ";", "// if the guzzle gets response http_status other than 200, it will throw an exception even when there is response available", "try", "{", "$", "response", "=", "$", "this", "->", "post", "(", "$", "params", ")", ";", "return", "MapperUtil", "::", "mapResponse", "(", "$", "response", ",", "new", "AuthCodes", "(", ")", ",", "$", "this", "->", "logger", ")", ";", "}", "catch", "(", "ClientException", "$", "e", ")", "{", "throw", "$", "this", "->", "mapError", "(", "$", "e", ",", "'Error requesting device codes.'", ")", ";", "}", "}" ]
Function to get device verification codes. @return mixed @throws ClientError @throws ApiError @throws AuthError @throws Exception
[ "Function", "to", "get", "device", "verification", "codes", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Auth/OauthProvider.php#L254-L271
29,628
secucard/secucard-connect-php-sdk
src/SecucardConnect/Auth/OauthProvider.php
OauthProvider.pollDeviceAccessToken
private function pollDeviceAccessToken($deviceCode) { if (!$this->credentials instanceof DeviceCredentials) { throw new ClientError('Invalid credentials set up, must be of type ' . DeviceCredentials::class); } $this->credentials->deviceCode = $deviceCode; $params = []; $this->setParams($params, $this->credentials); try { $response = $this->post($params); return MapperUtil::mapResponse($response); } catch (Exception $e) { // check for auth pending case $err = $this->mapError($e, 'Error during device authentication.'); if ($err instanceof AuthDeniedException && $err->getError() != null && $err->getError()->error === 'authorization_pending' ) { return false; } throw $err; } finally { // must reset to be ready for new auth attempt $this->credentials->deviceCode = null; } }
php
private function pollDeviceAccessToken($deviceCode) { if (!$this->credentials instanceof DeviceCredentials) { throw new ClientError('Invalid credentials set up, must be of type ' . DeviceCredentials::class); } $this->credentials->deviceCode = $deviceCode; $params = []; $this->setParams($params, $this->credentials); try { $response = $this->post($params); return MapperUtil::mapResponse($response); } catch (Exception $e) { // check for auth pending case $err = $this->mapError($e, 'Error during device authentication.'); if ($err instanceof AuthDeniedException && $err->getError() != null && $err->getError()->error === 'authorization_pending' ) { return false; } throw $err; } finally { // must reset to be ready for new auth attempt $this->credentials->deviceCode = null; } }
[ "private", "function", "pollDeviceAccessToken", "(", "$", "deviceCode", ")", "{", "if", "(", "!", "$", "this", "->", "credentials", "instanceof", "DeviceCredentials", ")", "{", "throw", "new", "ClientError", "(", "'Invalid credentials set up, must be of type '", ".", "DeviceCredentials", "::", "class", ")", ";", "}", "$", "this", "->", "credentials", "->", "deviceCode", "=", "$", "deviceCode", ";", "$", "params", "=", "[", "]", ";", "$", "this", "->", "setParams", "(", "$", "params", ",", "$", "this", "->", "credentials", ")", ";", "try", "{", "$", "response", "=", "$", "this", "->", "post", "(", "$", "params", ")", ";", "return", "MapperUtil", "::", "mapResponse", "(", "$", "response", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// check for auth pending case", "$", "err", "=", "$", "this", "->", "mapError", "(", "$", "e", ",", "'Error during device authentication.'", ")", ";", "if", "(", "$", "err", "instanceof", "AuthDeniedException", "&&", "$", "err", "->", "getError", "(", ")", "!=", "null", "&&", "$", "err", "->", "getError", "(", ")", "->", "error", "===", "'authorization_pending'", ")", "{", "return", "false", ";", "}", "throw", "$", "err", ";", "}", "finally", "{", "// must reset to be ready for new auth attempt", "$", "this", "->", "credentials", "->", "deviceCode", "=", "null", ";", "}", "}" ]
Function to get access token data for device authorization. This method may be invoked multiple times until it returns the token data. @param string $deviceCode The device code obtained by obtainDeviceVerification(). @throws \Exception If a error happens. @return mixed | boolean Returns false if the authorization is still pending on server side and the access token data on success.
[ "Function", "to", "get", "access", "token", "data", "for", "device", "authorization", ".", "This", "method", "may", "be", "invoked", "multiple", "times", "until", "it", "returns", "the", "token", "data", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Auth/OauthProvider.php#L281-L308
29,629
secucard/secucard-connect-php-sdk
src/SecucardConnect/Product/Smart/TransactionsService.php
TransactionsService.prepare
public function prepare($transactionId, $type, $object = null) { if (!in_array( $type, [ self::TYPE_AUTO, self::TYPE_DIRECT_DEBIT, self::TYPE_CREDIT_CARD, self::TYPE_INVOICE, self::TYPE_PAYPAL, ] )) { throw new \InvalidArgumentException('Wrong transaction type'); } return $this->execute($transactionId, 'prepare', $type, $object, Transaction::class); }
php
public function prepare($transactionId, $type, $object = null) { if (!in_array( $type, [ self::TYPE_AUTO, self::TYPE_DIRECT_DEBIT, self::TYPE_CREDIT_CARD, self::TYPE_INVOICE, self::TYPE_PAYPAL, ] )) { throw new \InvalidArgumentException('Wrong transaction type'); } return $this->execute($transactionId, 'prepare', $type, $object, Transaction::class); }
[ "public", "function", "prepare", "(", "$", "transactionId", ",", "$", "type", ",", "$", "object", "=", "null", ")", "{", "if", "(", "!", "in_array", "(", "$", "type", ",", "[", "self", "::", "TYPE_AUTO", ",", "self", "::", "TYPE_DIRECT_DEBIT", ",", "self", "::", "TYPE_CREDIT_CARD", ",", "self", "::", "TYPE_INVOICE", ",", "self", "::", "TYPE_PAYPAL", ",", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Wrong transaction type'", ")", ";", "}", "return", "$", "this", "->", "execute", "(", "$", "transactionId", ",", "'prepare'", ",", "$", "type", ",", "$", "object", ",", "Transaction", "::", "class", ")", ";", "}" ]
Preparing a transaction. @param string $transactionId The transaction id. @param string $type The transaction type like "auto" or "cash". @param null $object @return Transaction The prepared transaction. @throws GuzzleException @throws ApiError @throws AuthError @throws ClientError
[ "Preparing", "a", "transaction", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Product/Smart/TransactionsService.php#L60-L76
29,630
ventoviro/windwalker-core
src/Core/Mailer/MailAttachment.php
MailAttachment.getBody
public function getBody() { if ($this->body instanceof \Closure) { $method = $this->body; $this->body = $method(); } return $this->body; }
php
public function getBody() { if ($this->body instanceof \Closure) { $method = $this->body; $this->body = $method(); } return $this->body; }
[ "public", "function", "getBody", "(", ")", "{", "if", "(", "$", "this", "->", "body", "instanceof", "\\", "Closure", ")", "{", "$", "method", "=", "$", "this", "->", "body", ";", "$", "this", "->", "body", "=", "$", "method", "(", ")", ";", "}", "return", "$", "this", "->", "body", ";", "}" ]
Method to get property Body @return string
[ "Method", "to", "get", "property", "Body" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Mailer/MailAttachment.php#L133-L142
29,631
ventoviro/windwalker-core
src/Core/Schedule/Schedule.php
Schedule.getEvents
public function getEvents(array $tags = []): array { if ($tags === []) { return $this->events; } return array_filter($this->events, function (ScheduleEvent $event) use ($tags) { return array_intersect($event->getTags(), $tags) === $tags; }); }
php
public function getEvents(array $tags = []): array { if ($tags === []) { return $this->events; } return array_filter($this->events, function (ScheduleEvent $event) use ($tags) { return array_intersect($event->getTags(), $tags) === $tags; }); }
[ "public", "function", "getEvents", "(", "array", "$", "tags", "=", "[", "]", ")", ":", "array", "{", "if", "(", "$", "tags", "===", "[", "]", ")", "{", "return", "$", "this", "->", "events", ";", "}", "return", "array_filter", "(", "$", "this", "->", "events", ",", "function", "(", "ScheduleEvent", "$", "event", ")", "use", "(", "$", "tags", ")", "{", "return", "array_intersect", "(", "$", "event", "->", "getTags", "(", ")", ",", "$", "tags", ")", "===", "$", "tags", ";", "}", ")", ";", "}" ]
Method to get property Events @param array $tags @return ScheduleEvent[] @since 3.5.3
[ "Method", "to", "get", "property", "Events" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Schedule/Schedule.php#L279-L288
29,632
ventoviro/windwalker-core
src/Core/View/Traits/LayoutRenderableTrait.php
LayoutRenderableTrait.setRenderer
public function setRenderer($renderer) { $this->renderer = $renderer instanceof AbstractRenderer ?: $this->getRendererManager()->getRenderer((string) $renderer); return $this; }
php
public function setRenderer($renderer) { $this->renderer = $renderer instanceof AbstractRenderer ?: $this->getRendererManager()->getRenderer((string) $renderer); return $this; }
[ "public", "function", "setRenderer", "(", "$", "renderer", ")", "{", "$", "this", "->", "renderer", "=", "$", "renderer", "instanceof", "AbstractRenderer", "?", ":", "$", "this", "->", "getRendererManager", "(", ")", "->", "getRenderer", "(", "(", "string", ")", "$", "renderer", ")", ";", "return", "$", "this", ";", "}" ]
Method to set property renderer @param AbstractRenderer|string $renderer @return static Return self to support chaining.
[ "Method", "to", "set", "property", "renderer" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/View/Traits/LayoutRenderableTrait.php#L89-L94
29,633
ventoviro/windwalker-core
src/Core/View/Traits/LayoutRenderableTrait.php
LayoutRenderableTrait.getRendererManager
public function getRendererManager() { if (!$this->rendererManager) { $this->rendererManager = $this->getPackage()->getContainer()->get('renderer.manager'); } return $this->rendererManager; }
php
public function getRendererManager() { if (!$this->rendererManager) { $this->rendererManager = $this->getPackage()->getContainer()->get('renderer.manager'); } return $this->rendererManager; }
[ "public", "function", "getRendererManager", "(", ")", "{", "if", "(", "!", "$", "this", "->", "rendererManager", ")", "{", "$", "this", "->", "rendererManager", "=", "$", "this", "->", "getPackage", "(", ")", "->", "getContainer", "(", ")", "->", "get", "(", "'renderer.manager'", ")", ";", "}", "return", "$", "this", "->", "rendererManager", ";", "}" ]
Method to get property RendererManager @return RendererManager
[ "Method", "to", "get", "property", "RendererManager" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/View/Traits/LayoutRenderableTrait.php#L248-L255
29,634
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraCache.php
FedoraCache.deleteByUri
public function deleteByUri(string $uri) { if (!isset($this->cache[$uri])) { throw new NotInCache(); } foreach ($this->uri2id[$uri] as $id) { unset($this->id2uri[$id]); } unset($this->uri2id[$uri]); unset($this->cache[$uri]); }
php
public function deleteByUri(string $uri) { if (!isset($this->cache[$uri])) { throw new NotInCache(); } foreach ($this->uri2id[$uri] as $id) { unset($this->id2uri[$id]); } unset($this->uri2id[$uri]); unset($this->cache[$uri]); }
[ "public", "function", "deleteByUri", "(", "string", "$", "uri", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "cache", "[", "$", "uri", "]", ")", ")", "{", "throw", "new", "NotInCache", "(", ")", ";", "}", "foreach", "(", "$", "this", "->", "uri2id", "[", "$", "uri", "]", "as", "$", "id", ")", "{", "unset", "(", "$", "this", "->", "id2uri", "[", "$", "id", "]", ")", ";", "}", "unset", "(", "$", "this", "->", "uri2id", "[", "$", "uri", "]", ")", ";", "unset", "(", "$", "this", "->", "cache", "[", "$", "uri", "]", ")", ";", "}" ]
Removes given resource from cache. @param string $uri resource URI
[ "Removes", "given", "resource", "from", "cache", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraCache.php#L77-L86
29,635
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraCache.php
FedoraCache.deleteById
public function deleteById(string $id) { if (!isset($this->id2uri[$id])) { throw new NotInCache(); } $this->deleteByUri($this->id2uri[$id]); }
php
public function deleteById(string $id) { if (!isset($this->id2uri[$id])) { throw new NotInCache(); } $this->deleteByUri($this->id2uri[$id]); }
[ "public", "function", "deleteById", "(", "string", "$", "id", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "id2uri", "[", "$", "id", "]", ")", ")", "{", "throw", "new", "NotInCache", "(", ")", ";", "}", "$", "this", "->", "deleteByUri", "(", "$", "this", "->", "id2uri", "[", "$", "id", "]", ")", ";", "}" ]
Removes resource with a given internal id from cache. @param string $id resource repo internal id @throws NotInCache
[ "Removes", "resource", "with", "a", "given", "internal", "id", "from", "cache", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraCache.php#L93-L98
29,636
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraCache.php
FedoraCache.reload
public function reload(FedoraResource $res) { if (isset($this->cache[$res->getUri(true)])) { $this->delete($res); } $this->add($res); }
php
public function reload(FedoraResource $res) { if (isset($this->cache[$res->getUri(true)])) { $this->delete($res); } $this->add($res); }
[ "public", "function", "reload", "(", "FedoraResource", "$", "res", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "cache", "[", "$", "res", "->", "getUri", "(", "true", ")", "]", ")", ")", "{", "$", "this", "->", "delete", "(", "$", "res", ")", ";", "}", "$", "this", "->", "add", "(", "$", "res", ")", ";", "}" ]
Refreshes given resource in cache. @param FedoraResource $res resource object
[ "Refreshes", "given", "resource", "in", "cache", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraCache.php#L112-L117
29,637
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraCache.php
FedoraCache.add
public function add(FedoraResource $res) { $uri = $res->getUri(true); if (isset($this->cache[$uri])) { if (get_class($res) === get_class($this->cache[$uri])) { throw new AlreadyInCache(); } else { $this->deleteByUri($uri); } } try { $ids = $res->getIds(); $this->cache[$uri] = $res; $this->uri2id[$uri] = array(); foreach ($ids as $id) { $this->uri2id[$uri][] = $id; $this->id2uri[$id] = $uri; } } catch (ClientException $e) { switch ($e->getCode()) { case 404: throw new NotFound(); case 410: throw new Deleted(); default: throw $e; } } }
php
public function add(FedoraResource $res) { $uri = $res->getUri(true); if (isset($this->cache[$uri])) { if (get_class($res) === get_class($this->cache[$uri])) { throw new AlreadyInCache(); } else { $this->deleteByUri($uri); } } try { $ids = $res->getIds(); $this->cache[$uri] = $res; $this->uri2id[$uri] = array(); foreach ($ids as $id) { $this->uri2id[$uri][] = $id; $this->id2uri[$id] = $uri; } } catch (ClientException $e) { switch ($e->getCode()) { case 404: throw new NotFound(); case 410: throw new Deleted(); default: throw $e; } } }
[ "public", "function", "add", "(", "FedoraResource", "$", "res", ")", "{", "$", "uri", "=", "$", "res", "->", "getUri", "(", "true", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "cache", "[", "$", "uri", "]", ")", ")", "{", "if", "(", "get_class", "(", "$", "res", ")", "===", "get_class", "(", "$", "this", "->", "cache", "[", "$", "uri", "]", ")", ")", "{", "throw", "new", "AlreadyInCache", "(", ")", ";", "}", "else", "{", "$", "this", "->", "deleteByUri", "(", "$", "uri", ")", ";", "}", "}", "try", "{", "$", "ids", "=", "$", "res", "->", "getIds", "(", ")", ";", "$", "this", "->", "cache", "[", "$", "uri", "]", "=", "$", "res", ";", "$", "this", "->", "uri2id", "[", "$", "uri", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "ids", "as", "$", "id", ")", "{", "$", "this", "->", "uri2id", "[", "$", "uri", "]", "[", "]", "=", "$", "id", ";", "$", "this", "->", "id2uri", "[", "$", "id", "]", "=", "$", "uri", ";", "}", "}", "catch", "(", "ClientException", "$", "e", ")", "{", "switch", "(", "$", "e", "->", "getCode", "(", ")", ")", "{", "case", "404", ":", "throw", "new", "NotFound", "(", ")", ";", "case", "410", ":", "throw", "new", "Deleted", "(", ")", ";", "default", ":", "throw", "$", "e", ";", "}", "}", "}" ]
Adds given object to the cache. @param FedoraResource $res resource object @throws AlreadyInCache @throws NotFound @throws Deleted @throws ClientException
[ "Adds", "given", "object", "to", "the", "cache", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraCache.php#L127-L154
29,638
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraCache.php
FedoraCache.getById
public function getById(string $id): FedoraResource { if (!isset($this->id2uri[$id])) { throw new NotInCache(); } return $this->cache[$this->id2uri[$id]]; }
php
public function getById(string $id): FedoraResource { if (!isset($this->id2uri[$id])) { throw new NotInCache(); } return $this->cache[$this->id2uri[$id]]; }
[ "public", "function", "getById", "(", "string", "$", "id", ")", ":", "FedoraResource", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "id2uri", "[", "$", "id", "]", ")", ")", "{", "throw", "new", "NotInCache", "(", ")", ";", "}", "return", "$", "this", "->", "cache", "[", "$", "this", "->", "id2uri", "[", "$", "id", "]", "]", ";", "}" ]
Gets a resource from cache by its repo internal id. @param string $id resource's repo internal id @return FedoraResource @throws NotInCache
[ "Gets", "a", "resource", "from", "cache", "by", "its", "repo", "internal", "id", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraCache.php#L162-L167
29,639
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/FedoraCache.php
FedoraCache.getByUri
public function getByUri(string $uri): FedoraResource { if (!isset($this->cache[$uri])) { throw new NotInCache(); } return $this->cache[$uri]; }
php
public function getByUri(string $uri): FedoraResource { if (!isset($this->cache[$uri])) { throw new NotInCache(); } return $this->cache[$uri]; }
[ "public", "function", "getByUri", "(", "string", "$", "uri", ")", ":", "FedoraResource", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "cache", "[", "$", "uri", "]", ")", ")", "{", "throw", "new", "NotInCache", "(", ")", ";", "}", "return", "$", "this", "->", "cache", "[", "$", "uri", "]", ";", "}" ]
Gets a resource from cache by its URI. @param string $uri resource URI @return FedoraResource @throws NotInCache
[ "Gets", "a", "resource", "from", "cache", "by", "its", "URI", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/FedoraCache.php#L175-L180
29,640
secucard/secucard-connect-php-sdk
src/SecucardConnect/Event/EventDispatcher.php
EventDispatcher.dispatch
public function dispatch($eventStr) { try { // decode as array because data proprty, which has unknown structure (only known by handler), // must remain array after mapping to event $arr = MapperUtil::jsonDecode($eventStr, true); $event = MapperUtil::map($arr, Event::class); } catch (Exception $e) { throw new ClientError("Invalid event JSON", $e); } foreach ($this->handlerMap as $callback) { try { if ($callback->handle($event)) { return; } } catch (Exception $e) { if (!$e instanceof AbstractError) { throw new ClientError("Unknown error processing the event", $e); } else { throw $e; } } } }
php
public function dispatch($eventStr) { try { // decode as array because data proprty, which has unknown structure (only known by handler), // must remain array after mapping to event $arr = MapperUtil::jsonDecode($eventStr, true); $event = MapperUtil::map($arr, Event::class); } catch (Exception $e) { throw new ClientError("Invalid event JSON", $e); } foreach ($this->handlerMap as $callback) { try { if ($callback->handle($event)) { return; } } catch (Exception $e) { if (!$e instanceof AbstractError) { throw new ClientError("Unknown error processing the event", $e); } else { throw $e; } } } }
[ "public", "function", "dispatch", "(", "$", "eventStr", ")", "{", "try", "{", "// decode as array because data proprty, which has unknown structure (only known by handler),", "// must remain array after mapping to event", "$", "arr", "=", "MapperUtil", "::", "jsonDecode", "(", "$", "eventStr", ",", "true", ")", ";", "$", "event", "=", "MapperUtil", "::", "map", "(", "$", "arr", ",", "Event", "::", "class", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "ClientError", "(", "\"Invalid event JSON\"", ",", "$", "e", ")", ";", "}", "foreach", "(", "$", "this", "->", "handlerMap", "as", "$", "callback", ")", "{", "try", "{", "if", "(", "$", "callback", "->", "handle", "(", "$", "event", ")", ")", "{", "return", ";", "}", "}", "catch", "(", "Exception", "$", "e", ")", "{", "if", "(", "!", "$", "e", "instanceof", "AbstractError", ")", "{", "throw", "new", "ClientError", "(", "\"Unknown error processing the event\"", ",", "$", "e", ")", ";", "}", "else", "{", "throw", "$", "e", ";", "}", "}", "}", "}" ]
Dispatch the event string to a responsible handler if any. @param string $eventStr The event JSON. @return void @throws AbstractError
[ "Dispatch", "the", "event", "string", "to", "a", "responsible", "handler", "if", "any", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Event/EventDispatcher.php#L42-L66
29,641
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/FileStorage.php
FileStorage.set
public function set($key, $value) { // take care about replacing keys ! if (is_resource($value) || $value instanceof StreamInterface) { $res = file_put_contents($this->filePath($key), $value); if ($res !== false) { // clear plain storage from key return $this->deleteStore($key); } return $res; } else { $this->storage[$key] = $value; $res = $this->save(); if ($res !== false) { // clear file storage from key return $this->deleteFile($key); } return $res; } }
php
public function set($key, $value) { // take care about replacing keys ! if (is_resource($value) || $value instanceof StreamInterface) { $res = file_put_contents($this->filePath($key), $value); if ($res !== false) { // clear plain storage from key return $this->deleteStore($key); } return $res; } else { $this->storage[$key] = $value; $res = $this->save(); if ($res !== false) { // clear file storage from key return $this->deleteFile($key); } return $res; } }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ")", "{", "// take care about replacing keys !", "if", "(", "is_resource", "(", "$", "value", ")", "||", "$", "value", "instanceof", "StreamInterface", ")", "{", "$", "res", "=", "file_put_contents", "(", "$", "this", "->", "filePath", "(", "$", "key", ")", ",", "$", "value", ")", ";", "if", "(", "$", "res", "!==", "false", ")", "{", "// clear plain storage from key", "return", "$", "this", "->", "deleteStore", "(", "$", "key", ")", ";", "}", "return", "$", "res", ";", "}", "else", "{", "$", "this", "->", "storage", "[", "$", "key", "]", "=", "$", "value", ";", "$", "res", "=", "$", "this", "->", "save", "(", ")", ";", "if", "(", "$", "res", "!==", "false", ")", "{", "// clear file storage from key", "return", "$", "this", "->", "deleteFile", "(", "$", "key", ")", ";", "}", "return", "$", "res", ";", "}", "}" ]
Set an item in the cache @param string $key @param mixed $value @return bool
[ "Set", "an", "item", "in", "the", "cache" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/FileStorage.php#L68-L87
29,642
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/FileStorage.php
FileStorage.delete
public function delete($key) { $res = $this->deleteFile($key); if ($res === false) { return false; } return $this->deleteStore($key); }
php
public function delete($key) { $res = $this->deleteFile($key); if ($res === false) { return false; } return $this->deleteStore($key); }
[ "public", "function", "delete", "(", "$", "key", ")", "{", "$", "res", "=", "$", "this", "->", "deleteFile", "(", "$", "key", ")", ";", "if", "(", "$", "res", "===", "false", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "deleteStore", "(", "$", "key", ")", ";", "}" ]
Remove a key from the cache. @param string $key @return bool
[ "Remove", "a", "key", "from", "the", "cache", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/FileStorage.php#L96-L104
29,643
polyfony-inc/polyfony
Private/Polyfony/Mail.php
Mail.configureEnvironmentSpecifics
private function configureEnvironmentSpecifics() { // if we are in production we set the actual recipients if(Config::isProd()) { // set the main recipients foreach($this->recipients['to'] as $mail => $name) { // add to the mailer $this->mailer->addAddress($mail, $name); } // set the carbon copy recipients foreach($this->recipients['cc'] as $mail => $name) { // add to the mailer $this->mailer->addCC($mail, $name); } // set the hidden recipients foreach($this->recipients['bcc'] as $mail => $name) { // add to the mailer $this->mailer->addBCC($mail, $name); } } // if we are in the development enviroment else { // add the bypass address only $this->mailer->addAddress(Config::get('mail', 'bypass_mail')); } }
php
private function configureEnvironmentSpecifics() { // if we are in production we set the actual recipients if(Config::isProd()) { // set the main recipients foreach($this->recipients['to'] as $mail => $name) { // add to the mailer $this->mailer->addAddress($mail, $name); } // set the carbon copy recipients foreach($this->recipients['cc'] as $mail => $name) { // add to the mailer $this->mailer->addCC($mail, $name); } // set the hidden recipients foreach($this->recipients['bcc'] as $mail => $name) { // add to the mailer $this->mailer->addBCC($mail, $name); } } // if we are in the development enviroment else { // add the bypass address only $this->mailer->addAddress(Config::get('mail', 'bypass_mail')); } }
[ "private", "function", "configureEnvironmentSpecifics", "(", ")", "{", "// if we are in production we set the actual recipients", "if", "(", "Config", "::", "isProd", "(", ")", ")", "{", "// set the main recipients", "foreach", "(", "$", "this", "->", "recipients", "[", "'to'", "]", "as", "$", "mail", "=>", "$", "name", ")", "{", "// add to the mailer", "$", "this", "->", "mailer", "->", "addAddress", "(", "$", "mail", ",", "$", "name", ")", ";", "}", "// set the carbon copy recipients", "foreach", "(", "$", "this", "->", "recipients", "[", "'cc'", "]", "as", "$", "mail", "=>", "$", "name", ")", "{", "// add to the mailer", "$", "this", "->", "mailer", "->", "addCC", "(", "$", "mail", ",", "$", "name", ")", ";", "}", "// set the hidden recipients", "foreach", "(", "$", "this", "->", "recipients", "[", "'bcc'", "]", "as", "$", "mail", "=>", "$", "name", ")", "{", "// add to the mailer", "$", "this", "->", "mailer", "->", "addBCC", "(", "$", "mail", ",", "$", "name", ")", ";", "}", "}", "// if we are in the development enviroment", "else", "{", "// add the bypass address only", "$", "this", "->", "mailer", "->", "addAddress", "(", "Config", "::", "get", "(", "'mail'", ",", "'bypass_mail'", ")", ")", ";", "}", "}" ]
this applies options that are only used in development, or only in production
[ "this", "applies", "options", "that", "are", "only", "used", "in", "development", "or", "only", "in", "production" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Mail.php#L303-L327
29,644
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.setLinks
public static function setLinks(array $links, bool $replace_existing=false) :void { // if we want to purge existing links !$replace_existing ?: self::$_links = []; // href is the key for storing links foreach($links as $href_or_index => $attributes_or_href) { // if arguments are provided if(is_array($attributes_or_href)) { // if we have a stylesheet if( // if a rel is set, and it's not a stylesheet !array_key_exists('rel',$attributes_or_href) || // and it's not a stylesheet $attributes_or_href['rel'] == 'stylesheet' ) { // also rewrite the path of assets that used relative shortcuts $attributes_or_href['href'] = self::getPublicAssetPath($href_or_index,'Css'); // force the type $attributes_or_href['type'] = 'text/css'; // force the rel $attributes_or_href['rel'] = 'stylesheet'; // if the media key is implicit array_key_exists('media', $attributes_or_href) ?: $attributes_or_href['media'] = 'all'; // push the slightly alternated stylesheet self::$_links[$href_or_index] = $attributes_or_href; } // otherwize we don't know what we're dealing with else { // just set its href $attributes_or_href['href'] = $href_or_index; // push that link and its attributes self::$_links[$href_or_index] = $attributes_or_href; } } // else only an href is provided, we assume it is a stylesheet else { // push that link alone self::$_links[$attributes_or_href] = [ // we assume it is a generic all media stylesheet 'rel' =>'stylesheet', 'type' =>'text/css', 'media' =>'all', // and we set its href 'href' =>self::getPublicAssetPath($attributes_or_href, 'Css') ]; } } }
php
public static function setLinks(array $links, bool $replace_existing=false) :void { // if we want to purge existing links !$replace_existing ?: self::$_links = []; // href is the key for storing links foreach($links as $href_or_index => $attributes_or_href) { // if arguments are provided if(is_array($attributes_or_href)) { // if we have a stylesheet if( // if a rel is set, and it's not a stylesheet !array_key_exists('rel',$attributes_or_href) || // and it's not a stylesheet $attributes_or_href['rel'] == 'stylesheet' ) { // also rewrite the path of assets that used relative shortcuts $attributes_or_href['href'] = self::getPublicAssetPath($href_or_index,'Css'); // force the type $attributes_or_href['type'] = 'text/css'; // force the rel $attributes_or_href['rel'] = 'stylesheet'; // if the media key is implicit array_key_exists('media', $attributes_or_href) ?: $attributes_or_href['media'] = 'all'; // push the slightly alternated stylesheet self::$_links[$href_or_index] = $attributes_or_href; } // otherwize we don't know what we're dealing with else { // just set its href $attributes_or_href['href'] = $href_or_index; // push that link and its attributes self::$_links[$href_or_index] = $attributes_or_href; } } // else only an href is provided, we assume it is a stylesheet else { // push that link alone self::$_links[$attributes_or_href] = [ // we assume it is a generic all media stylesheet 'rel' =>'stylesheet', 'type' =>'text/css', 'media' =>'all', // and we set its href 'href' =>self::getPublicAssetPath($attributes_or_href, 'Css') ]; } } }
[ "public", "static", "function", "setLinks", "(", "array", "$", "links", ",", "bool", "$", "replace_existing", "=", "false", ")", ":", "void", "{", "// if we want to purge existing links", "!", "$", "replace_existing", "?", ":", "self", "::", "$", "_links", "=", "[", "]", ";", "// href is the key for storing links", "foreach", "(", "$", "links", "as", "$", "href_or_index", "=>", "$", "attributes_or_href", ")", "{", "// if arguments are provided", "if", "(", "is_array", "(", "$", "attributes_or_href", ")", ")", "{", "// if we have a stylesheet", "if", "(", "// if a rel is set, and it's not a stylesheet", "!", "array_key_exists", "(", "'rel'", ",", "$", "attributes_or_href", ")", "||", "// and it's not a stylesheet", "$", "attributes_or_href", "[", "'rel'", "]", "==", "'stylesheet'", ")", "{", "// also rewrite the path of assets that used relative shortcuts", "$", "attributes_or_href", "[", "'href'", "]", "=", "self", "::", "getPublicAssetPath", "(", "$", "href_or_index", ",", "'Css'", ")", ";", "// force the type", "$", "attributes_or_href", "[", "'type'", "]", "=", "'text/css'", ";", "// force the rel", "$", "attributes_or_href", "[", "'rel'", "]", "=", "'stylesheet'", ";", "// if the media key is implicit", "array_key_exists", "(", "'media'", ",", "$", "attributes_or_href", ")", "?", ":", "$", "attributes_or_href", "[", "'media'", "]", "=", "'all'", ";", "// push the slightly alternated stylesheet", "self", "::", "$", "_links", "[", "$", "href_or_index", "]", "=", "$", "attributes_or_href", ";", "}", "// otherwize we don't know what we're dealing with", "else", "{", "// just set its href", "$", "attributes_or_href", "[", "'href'", "]", "=", "$", "href_or_index", ";", "// push that link and its attributes", "self", "::", "$", "_links", "[", "$", "href_or_index", "]", "=", "$", "attributes_or_href", ";", "}", "}", "// else only an href is provided, we assume it is a stylesheet", "else", "{", "// push that link alone", "self", "::", "$", "_links", "[", "$", "attributes_or_href", "]", "=", "[", "// we assume it is a generic all media stylesheet", "'rel'", "=>", "'stylesheet'", ",", "'type'", "=>", "'text/css'", ",", "'media'", "=>", "'all'", ",", "// and we set its href", "'href'", "=>", "self", "::", "getPublicAssetPath", "(", "$", "attributes_or_href", ",", "'Css'", ")", "]", ";", "}", "}", "}" ]
set links for the current HTML page
[ "set", "links", "for", "the", "current", "HTML", "page" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L15-L61
29,645
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.setScripts
public static function setScripts(array $scripts, bool $replace_existing=false) :void { // if we want to purge existing scripts !$replace_existing ?: self::$_scripts = []; // for each script we have to set foreach($scripts as $script) { // rewrite its path self::$_scripts[] = self::getPublicAssetPath($script, 'Js'); } }
php
public static function setScripts(array $scripts, bool $replace_existing=false) :void { // if we want to purge existing scripts !$replace_existing ?: self::$_scripts = []; // for each script we have to set foreach($scripts as $script) { // rewrite its path self::$_scripts[] = self::getPublicAssetPath($script, 'Js'); } }
[ "public", "static", "function", "setScripts", "(", "array", "$", "scripts", ",", "bool", "$", "replace_existing", "=", "false", ")", ":", "void", "{", "// if we want to purge existing scripts", "!", "$", "replace_existing", "?", ":", "self", "::", "$", "_scripts", "=", "[", "]", ";", "// for each script we have to set", "foreach", "(", "$", "scripts", "as", "$", "script", ")", "{", "// rewrite its path", "self", "::", "$", "_scripts", "[", "]", "=", "self", "::", "getPublicAssetPath", "(", "$", "script", ",", "'Js'", ")", ";", "}", "}" ]
set scripts for the current HTML page
[ "set", "scripts", "for", "the", "current", "HTML", "page" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L64-L72
29,646
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.setMetas
public static function setMetas(array $metas, bool $replace_existing=false) :void { // if we want to purge existing metas !$replace_existing ?: self::$_metas = []; // name is the key for storing metas self::$_metas += $metas; }
php
public static function setMetas(array $metas, bool $replace_existing=false) :void { // if we want to purge existing metas !$replace_existing ?: self::$_metas = []; // name is the key for storing metas self::$_metas += $metas; }
[ "public", "static", "function", "setMetas", "(", "array", "$", "metas", ",", "bool", "$", "replace_existing", "=", "false", ")", ":", "void", "{", "// if we want to purge existing metas", "!", "$", "replace_existing", "?", ":", "self", "::", "$", "_metas", "=", "[", "]", ";", "// name is the key for storing metas", "self", "::", "$", "_metas", "+=", "$", "metas", ";", "}" ]
set metas for the current HTML page
[ "set", "metas", "for", "the", "current", "HTML", "page" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L76-L81
29,647
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.set
public static function set(array $assets) :void { // for each batch foreach($assets as $category => $scripts_or_links_or_metas) { // if the batch is scripts if($category == 'scripts') { self::setScripts($scripts_or_links_or_metas); } // if the batch is links elseif($category == 'links') { self::setLinks($scripts_or_links_or_metas); } // if the match is metas elseif($category == 'metas') { self::setMetas($scripts_or_links_or_metas); } } }
php
public static function set(array $assets) :void { // for each batch foreach($assets as $category => $scripts_or_links_or_metas) { // if the batch is scripts if($category == 'scripts') { self::setScripts($scripts_or_links_or_metas); } // if the batch is links elseif($category == 'links') { self::setLinks($scripts_or_links_or_metas); } // if the match is metas elseif($category == 'metas') { self::setMetas($scripts_or_links_or_metas); } } }
[ "public", "static", "function", "set", "(", "array", "$", "assets", ")", ":", "void", "{", "// for each batch", "foreach", "(", "$", "assets", "as", "$", "category", "=>", "$", "scripts_or_links_or_metas", ")", "{", "// if the batch is scripts", "if", "(", "$", "category", "==", "'scripts'", ")", "{", "self", "::", "setScripts", "(", "$", "scripts_or_links_or_metas", ")", ";", "}", "// if the batch is links", "elseif", "(", "$", "category", "==", "'links'", ")", "{", "self", "::", "setLinks", "(", "$", "scripts_or_links_or_metas", ")", ";", "}", "// if the match is metas", "elseif", "(", "$", "category", "==", "'metas'", ")", "{", "self", "::", "setMetas", "(", "$", "scripts_or_links_or_metas", ")", ";", "}", "}", "}" ]
shortcuts to quickly set multiple things
[ "shortcuts", "to", "quickly", "set", "multiple", "things" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L84-L100
29,648
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.buildAndGetPage
public static function buildAndGetPage(string $content) :string { // initial content $page = '<!doctype html><html lang="'.\Polyfony\Locales::getLanguage().'"><head><title>'.(isset(self::$_metas['title']) ? self::$_metas['title'] : '').'</title><meta http-equiv="content-type" content="text/html; charset=' . \Polyfony\Response::getCharset() . '" />'; // add the meta tags and the links $page .= self::buildMetasTags() . self::buildLinksTags(); // close the head, add the body, and add the scripts $page .= '</head><body>' . $content . self::buildScriptsTags(); // add the profiler (if enabled) $page .= \Polyfony\Config::get('profiler', 'enable') ? new \Polyfony\Profiler\HTML : ''; // close the document and return the assembled html page return $page . '</body></html>'; }
php
public static function buildAndGetPage(string $content) :string { // initial content $page = '<!doctype html><html lang="'.\Polyfony\Locales::getLanguage().'"><head><title>'.(isset(self::$_metas['title']) ? self::$_metas['title'] : '').'</title><meta http-equiv="content-type" content="text/html; charset=' . \Polyfony\Response::getCharset() . '" />'; // add the meta tags and the links $page .= self::buildMetasTags() . self::buildLinksTags(); // close the head, add the body, and add the scripts $page .= '</head><body>' . $content . self::buildScriptsTags(); // add the profiler (if enabled) $page .= \Polyfony\Config::get('profiler', 'enable') ? new \Polyfony\Profiler\HTML : ''; // close the document and return the assembled html page return $page . '</body></html>'; }
[ "public", "static", "function", "buildAndGetPage", "(", "string", "$", "content", ")", ":", "string", "{", "// initial content", "$", "page", "=", "'<!doctype html><html lang=\"'", ".", "\\", "Polyfony", "\\", "Locales", "::", "getLanguage", "(", ")", ".", "'\"><head><title>'", ".", "(", "isset", "(", "self", "::", "$", "_metas", "[", "'title'", "]", ")", "?", "self", "::", "$", "_metas", "[", "'title'", "]", ":", "''", ")", ".", "'</title><meta http-equiv=\"content-type\" content=\"text/html; charset='", ".", "\\", "Polyfony", "\\", "Response", "::", "getCharset", "(", ")", ".", "'\" />'", ";", "// add the meta tags and the links", "$", "page", ".=", "self", "::", "buildMetasTags", "(", ")", ".", "self", "::", "buildLinksTags", "(", ")", ";", "// close the head, add the body, and add the scripts", "$", "page", ".=", "'</head><body>'", ".", "$", "content", ".", "self", "::", "buildScriptsTags", "(", ")", ";", "// add the profiler (if enabled)", "$", "page", ".=", "\\", "Polyfony", "\\", "Config", "::", "get", "(", "'profiler'", ",", "'enable'", ")", "?", "new", "\\", "Polyfony", "\\", "Profiler", "\\", "HTML", ":", "''", ";", "// close the document and return the assembled html page", "return", "$", "page", ".", "'</body></html>'", ";", "}" ]
build an html page
[ "build", "an", "html", "page" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L103-L115
29,649
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.buildMetasTags
private static function buildMetasTags() :string { // this is where formatted meta tags go $metas = ''; // for each available meta foreach(self::$_metas as $name => $content) { // add the formated the meta $metas .= '<meta name="'.$name.'" content="'.\Polyfony\Format::htmlSafe($content).'" />'; } return $metas; }
php
private static function buildMetasTags() :string { // this is where formatted meta tags go $metas = ''; // for each available meta foreach(self::$_metas as $name => $content) { // add the formated the meta $metas .= '<meta name="'.$name.'" content="'.\Polyfony\Format::htmlSafe($content).'" />'; } return $metas; }
[ "private", "static", "function", "buildMetasTags", "(", ")", ":", "string", "{", "// this is where formatted meta tags go", "$", "metas", "=", "''", ";", "// for each available meta", "foreach", "(", "self", "::", "$", "_metas", "as", "$", "name", "=>", "$", "content", ")", "{", "// add the formated the meta", "$", "metas", ".=", "'<meta name=\"'", ".", "$", "name", ".", "'\" content=\"'", ".", "\\", "Polyfony", "\\", "Format", "::", "htmlSafe", "(", "$", "content", ")", ".", "'\" />'", ";", "}", "return", "$", "metas", ";", "}" ]
builds meta code
[ "builds", "meta", "code" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L120-L130
29,650
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.buildLinksTags
private static function buildLinksTags() :string { // this is where formatted links tags go $links = []; // pack and minify self::packAndMinifyLinks(); // for each available link foreach(self::$_links as $href => $attributes) { // sort the attributes (compulse order needs) ksort($attributes); // build as base stylesheet link and merge its attributes $links[] = new \Polyfony\Element('link', $attributes); } return implode('', $links); }
php
private static function buildLinksTags() :string { // this is where formatted links tags go $links = []; // pack and minify self::packAndMinifyLinks(); // for each available link foreach(self::$_links as $href => $attributes) { // sort the attributes (compulse order needs) ksort($attributes); // build as base stylesheet link and merge its attributes $links[] = new \Polyfony\Element('link', $attributes); } return implode('', $links); }
[ "private", "static", "function", "buildLinksTags", "(", ")", ":", "string", "{", "// this is where formatted links tags go", "$", "links", "=", "[", "]", ";", "// pack and minify", "self", "::", "packAndMinifyLinks", "(", ")", ";", "// for each available link", "foreach", "(", "self", "::", "$", "_links", "as", "$", "href", "=>", "$", "attributes", ")", "{", "// sort the attributes (compulse order needs)", "ksort", "(", "$", "attributes", ")", ";", "// build as base stylesheet link and merge its attributes", "$", "links", "[", "]", "=", "new", "\\", "Polyfony", "\\", "Element", "(", "'link'", ",", "$", "attributes", ")", ";", "}", "return", "implode", "(", "''", ",", "$", "links", ")", ";", "}" ]
build links code
[ "build", "links", "code" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L133-L146
29,651
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.doesThisPackNeedRegeneration
private static function doesThisPackNeedRegeneration(string $pack_path) :bool { return // if the file does not exist !file_exists($pack_path) || // or if we're not allowed to use cached items !\Polyfony\Config::get('response','cache') || // of if the request explicitely disallows that !\Polyfony\Request::isCacheAllowed(); }
php
private static function doesThisPackNeedRegeneration(string $pack_path) :bool { return // if the file does not exist !file_exists($pack_path) || // or if we're not allowed to use cached items !\Polyfony\Config::get('response','cache') || // of if the request explicitely disallows that !\Polyfony\Request::isCacheAllowed(); }
[ "private", "static", "function", "doesThisPackNeedRegeneration", "(", "string", "$", "pack_path", ")", ":", "bool", "{", "return", "// if the file does not exist", "!", "file_exists", "(", "$", "pack_path", ")", "||", "// or if we're not allowed to use cached items", "!", "\\", "Polyfony", "\\", "Config", "::", "get", "(", "'response'", ",", "'cache'", ")", "||", "// of if the request explicitely disallows that", "!", "\\", "Polyfony", "\\", "Request", "::", "isCacheAllowed", "(", ")", ";", "}" ]
if this pack needs to be generated again
[ "if", "this", "pack", "needs", "to", "be", "generated", "again" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L266-L274
29,652
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.getPublicAssetPath
private static function getPublicAssetPath(string $asset_path, string $asset_type) :string { // if the asset path is absolute in any way return (substr($asset_path,0,1) == '/' || substr($asset_path,0,4) == 'http') ? // it is returned as is, // otherwise it is made relative to the Assets folder $asset_path : "/Assets/{$asset_type}/$asset_path"; }
php
private static function getPublicAssetPath(string $asset_path, string $asset_type) :string { // if the asset path is absolute in any way return (substr($asset_path,0,1) == '/' || substr($asset_path,0,4) == 'http') ? // it is returned as is, // otherwise it is made relative to the Assets folder $asset_path : "/Assets/{$asset_type}/$asset_path"; }
[ "private", "static", "function", "getPublicAssetPath", "(", "string", "$", "asset_path", ",", "string", "$", "asset_type", ")", ":", "string", "{", "// if the asset path is absolute in any way", "return", "(", "substr", "(", "$", "asset_path", ",", "0", ",", "1", ")", "==", "'/'", "||", "substr", "(", "$", "asset_path", ",", "0", ",", "4", ")", "==", "'http'", ")", "?", "// it is returned as is, // otherwise it is made relative to the Assets folder", "$", "asset_path", ":", "\"/Assets/{$asset_type}/$asset_path\"", ";", "}" ]
assets path converter
[ "assets", "path", "converter" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L277-L282
29,653
polyfony-inc/polyfony
Private/Polyfony/Response/HTML.php
HTML.getMinifiedPackIfAllowed
private static function getMinifiedPackIfAllowed(string $pack_contents, object $packer_object=null) :string { // if we are allowed to minify return \Polyfony\Config::get('response','minify') ? ($packer_object)->add($pack_contents)->minify() : $pack_contents; }
php
private static function getMinifiedPackIfAllowed(string $pack_contents, object $packer_object=null) :string { // if we are allowed to minify return \Polyfony\Config::get('response','minify') ? ($packer_object)->add($pack_contents)->minify() : $pack_contents; }
[ "private", "static", "function", "getMinifiedPackIfAllowed", "(", "string", "$", "pack_contents", ",", "object", "$", "packer_object", "=", "null", ")", ":", "string", "{", "// if we are allowed to minify", "return", "\\", "Polyfony", "\\", "Config", "::", "get", "(", "'response'", ",", "'minify'", ")", "?", "(", "$", "packer_object", ")", "->", "add", "(", "$", "pack_contents", ")", "->", "minify", "(", ")", ":", "$", "pack_contents", ";", "}" ]
minify the packed content if it's allowed, otherwise return is at is
[ "minify", "the", "packed", "content", "if", "it", "s", "allowed", "otherwise", "return", "is", "at", "is" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Response/HTML.php#L294-L300
29,654
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.addMissingAttributes
public function addMissingAttributes() { foreach ($this->getSchema() as $key => $settings) { if (!array_has($this->attributes, $key)) { array_set($this->attributes, $key, array_get($settings, 'default', null)); } } }
php
public function addMissingAttributes() { foreach ($this->getSchema() as $key => $settings) { if (!array_has($this->attributes, $key)) { array_set($this->attributes, $key, array_get($settings, 'default', null)); } } }
[ "public", "function", "addMissingAttributes", "(", ")", "{", "foreach", "(", "$", "this", "->", "getSchema", "(", ")", "as", "$", "key", "=>", "$", "settings", ")", "{", "if", "(", "!", "array_has", "(", "$", "this", "->", "attributes", ",", "$", "key", ")", ")", "{", "array_set", "(", "$", "this", "->", "attributes", ",", "$", "key", ",", "array_get", "(", "$", "settings", ",", "'default'", ",", "null", ")", ")", ";", "}", "}", "}" ]
Set's mising attributes. This covers situations where values have defaults but are not fillable, or date field. @return void
[ "Set", "s", "mising", "attributes", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L109-L116
29,655
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.hasWriteAccess
public function hasWriteAccess($key) { if (static::$unguarded) { return true; } // Attribute is guarded. if (in_array($key, $this->getGuarded())) { return false; } if (($method = $this->getAuthMethod($key)) !== false) { return $this->$method($key); } // Check for the presence of a mutator for the auth operation // which simply lets the developers check if the current user // has the authority to update this value. if ($this->hasAuthAttributeMutator($key)) { $method = 'auth'.Str::studly($key).'Attribute'; return $this->{$method}($key); } return true; }
php
public function hasWriteAccess($key) { if (static::$unguarded) { return true; } // Attribute is guarded. if (in_array($key, $this->getGuarded())) { return false; } if (($method = $this->getAuthMethod($key)) !== false) { return $this->$method($key); } // Check for the presence of a mutator for the auth operation // which simply lets the developers check if the current user // has the authority to update this value. if ($this->hasAuthAttributeMutator($key)) { $method = 'auth'.Str::studly($key).'Attribute'; return $this->{$method}($key); } return true; }
[ "public", "function", "hasWriteAccess", "(", "$", "key", ")", "{", "if", "(", "static", "::", "$", "unguarded", ")", "{", "return", "true", ";", "}", "// Attribute is guarded.", "if", "(", "in_array", "(", "$", "key", ",", "$", "this", "->", "getGuarded", "(", ")", ")", ")", "{", "return", "false", ";", "}", "if", "(", "(", "$", "method", "=", "$", "this", "->", "getAuthMethod", "(", "$", "key", ")", ")", "!==", "false", ")", "{", "return", "$", "this", "->", "$", "method", "(", "$", "key", ")", ";", "}", "// Check for the presence of a mutator for the auth operation", "// which simply lets the developers check if the current user", "// has the authority to update this value.", "if", "(", "$", "this", "->", "hasAuthAttributeMutator", "(", "$", "key", ")", ")", "{", "$", "method", "=", "'auth'", ".", "Str", "::", "studly", "(", "$", "key", ")", ".", "'Attribute'", ";", "return", "$", "this", "->", "{", "$", "method", "}", "(", "$", "key", ")", ";", "}", "return", "true", ";", "}" ]
Has write access to a given key on this model. @param string $key @return bool
[ "Has", "write", "access", "to", "a", "given", "key", "on", "this", "model", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L145-L170
29,656
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.setDefaultValuesForAttributes
public function setDefaultValuesForAttributes() { // Only works on new models. if ($this->exists) { return $this; } // Defaults on attributes. $defaults = $this->getAttributesFromSchema('default', true); // Remove attributes that have been given values. $defaults = array_except($defaults, array_keys($this->getDirty())); // Unguard. static::unguard(); // Allocate values. foreach ($defaults as $key => $value) { $this->{$key} = $value; } // Reguard. static::reguard(); return $this; }
php
public function setDefaultValuesForAttributes() { // Only works on new models. if ($this->exists) { return $this; } // Defaults on attributes. $defaults = $this->getAttributesFromSchema('default', true); // Remove attributes that have been given values. $defaults = array_except($defaults, array_keys($this->getDirty())); // Unguard. static::unguard(); // Allocate values. foreach ($defaults as $key => $value) { $this->{$key} = $value; } // Reguard. static::reguard(); return $this; }
[ "public", "function", "setDefaultValuesForAttributes", "(", ")", "{", "// Only works on new models.", "if", "(", "$", "this", "->", "exists", ")", "{", "return", "$", "this", ";", "}", "// Defaults on attributes.", "$", "defaults", "=", "$", "this", "->", "getAttributesFromSchema", "(", "'default'", ",", "true", ")", ";", "// Remove attributes that have been given values.", "$", "defaults", "=", "array_except", "(", "$", "defaults", ",", "array_keys", "(", "$", "this", "->", "getDirty", "(", ")", ")", ")", ";", "// Unguard.", "static", "::", "unguard", "(", ")", ";", "// Allocate values.", "foreach", "(", "$", "defaults", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "{", "$", "key", "}", "=", "$", "value", ";", "}", "// Reguard.", "static", "::", "reguard", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set default values on this attribute. @return $this
[ "Set", "default", "values", "on", "this", "attribute", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L177-L202
29,657
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.getCastParams
public function getCastParams() { if ($this->getIncrementing()) { return array_merge( [ $this->getKeyName() => $this->getKeyType(), ], $this->getAttributesFromSchema('cast', true) ); } return $this->getAttributesFromSchema('cast-params', true); }
php
public function getCastParams() { if ($this->getIncrementing()) { return array_merge( [ $this->getKeyName() => $this->getKeyType(), ], $this->getAttributesFromSchema('cast', true) ); } return $this->getAttributesFromSchema('cast-params', true); }
[ "public", "function", "getCastParams", "(", ")", "{", "if", "(", "$", "this", "->", "getIncrementing", "(", ")", ")", "{", "return", "array_merge", "(", "[", "$", "this", "->", "getKeyName", "(", ")", "=>", "$", "this", "->", "getKeyType", "(", ")", ",", "]", ",", "$", "this", "->", "getAttributesFromSchema", "(", "'cast'", ",", "true", ")", ")", ";", "}", "return", "$", "this", "->", "getAttributesFromSchema", "(", "'cast-params'", ",", "true", ")", ";", "}" ]
Get the casts params array. @return array
[ "Get", "the", "casts", "params", "array", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L228-L240
29,658
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.getCastFromDefinition
protected function getCastFromDefinition($type) { // Custom definitions. if (array_has(static::$cast_from, $type)) { return array_get(static::$cast_from, $type); } // Fallback to default. if (array_has(static::$default_cast_from, $type)) { return array_get(static::$default_cast_from, $type); } return false; }
php
protected function getCastFromDefinition($type) { // Custom definitions. if (array_has(static::$cast_from, $type)) { return array_get(static::$cast_from, $type); } // Fallback to default. if (array_has(static::$default_cast_from, $type)) { return array_get(static::$default_cast_from, $type); } return false; }
[ "protected", "function", "getCastFromDefinition", "(", "$", "type", ")", "{", "// Custom definitions.", "if", "(", "array_has", "(", "static", "::", "$", "cast_from", ",", "$", "type", ")", ")", "{", "return", "array_get", "(", "static", "::", "$", "cast_from", ",", "$", "type", ")", ";", "}", "// Fallback to default.", "if", "(", "array_has", "(", "static", "::", "$", "default_cast_from", ",", "$", "type", ")", ")", "{", "return", "array_get", "(", "static", "::", "$", "default_cast_from", ",", "$", "type", ")", ";", "}", "return", "false", ";", "}" ]
Get the method to cast this attribte type. @param string $type @return string|array|bool
[ "Get", "the", "method", "to", "cast", "this", "attribte", "type", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L290-L303
29,659
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.getCastAsParamaters
protected function getCastAsParamaters($key) { $cast_params = $this->getCastParams(); $paramaters = explode(':', array_get($cast_params, $key, '')); $parsed = $this->parseCastParamaters($paramaters); return $parsed; }
php
protected function getCastAsParamaters($key) { $cast_params = $this->getCastParams(); $paramaters = explode(':', array_get($cast_params, $key, '')); $parsed = $this->parseCastParamaters($paramaters); return $parsed; }
[ "protected", "function", "getCastAsParamaters", "(", "$", "key", ")", "{", "$", "cast_params", "=", "$", "this", "->", "getCastParams", "(", ")", ";", "$", "paramaters", "=", "explode", "(", "':'", ",", "array_get", "(", "$", "cast_params", ",", "$", "key", ",", "''", ")", ")", ";", "$", "parsed", "=", "$", "this", "->", "parseCastParamaters", "(", "$", "paramaters", ")", ";", "return", "$", "parsed", ";", "}" ]
Get the method to cast this attribte tyepca. @param string $type @return string|array|bool
[ "Get", "the", "method", "to", "cast", "this", "attribte", "tyepca", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L312-L320
29,660
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.parseCastParamaters
private function parseCastParamaters($paramaters) { foreach ($paramaters as &$value) { // Local callable method. ($someMethod()) if (substr($value, 0, 1) === '$' && stripos($value, '()') !== false) { $method = substr($value, 1, -2); $value = is_callable([$this, $method]) ? $this->{$method}() : null; // Local attribute. ($some_attribute) } elseif (substr($value, 0, 1) === '$') { $key = substr($value, 1); $value = $this->{$key}; // Callable function (eg helper). (some_function()) } elseif (stripos($value, '()') !== false) { $method = substr($value, 0, -2); $value = is_callable($method) ? $method() : null; } // String value. } return $paramaters; }
php
private function parseCastParamaters($paramaters) { foreach ($paramaters as &$value) { // Local callable method. ($someMethod()) if (substr($value, 0, 1) === '$' && stripos($value, '()') !== false) { $method = substr($value, 1, -2); $value = is_callable([$this, $method]) ? $this->{$method}() : null; // Local attribute. ($some_attribute) } elseif (substr($value, 0, 1) === '$') { $key = substr($value, 1); $value = $this->{$key}; // Callable function (eg helper). (some_function()) } elseif (stripos($value, '()') !== false) { $method = substr($value, 0, -2); $value = is_callable($method) ? $method() : null; } // String value. } return $paramaters; }
[ "private", "function", "parseCastParamaters", "(", "$", "paramaters", ")", "{", "foreach", "(", "$", "paramaters", "as", "&", "$", "value", ")", "{", "// Local callable method. ($someMethod())", "if", "(", "substr", "(", "$", "value", ",", "0", ",", "1", ")", "===", "'$'", "&&", "stripos", "(", "$", "value", ",", "'()'", ")", "!==", "false", ")", "{", "$", "method", "=", "substr", "(", "$", "value", ",", "1", ",", "-", "2", ")", ";", "$", "value", "=", "is_callable", "(", "[", "$", "this", ",", "$", "method", "]", ")", "?", "$", "this", "->", "{", "$", "method", "}", "(", ")", ":", "null", ";", "// Local attribute. ($some_attribute)", "}", "elseif", "(", "substr", "(", "$", "value", ",", "0", ",", "1", ")", "===", "'$'", ")", "{", "$", "key", "=", "substr", "(", "$", "value", ",", "1", ")", ";", "$", "value", "=", "$", "this", "->", "{", "$", "key", "}", ";", "// Callable function (eg helper). (some_function())", "}", "elseif", "(", "stripos", "(", "$", "value", ",", "'()'", ")", "!==", "false", ")", "{", "$", "method", "=", "substr", "(", "$", "value", ",", "0", ",", "-", "2", ")", ";", "$", "value", "=", "is_callable", "(", "$", "method", ")", "?", "$", "method", "(", ")", ":", "null", ";", "}", "// String value.", "}", "return", "$", "paramaters", ";", "}" ]
Parse the given cast parameters. @param array $paramaters @return array
[ "Parse", "the", "given", "cast", "parameters", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L329-L352
29,661
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.getAuthMethod
public function getAuthMethod($key) { if (array_has($this->getAuths(), $key)) { $method = 'auth'.studly_case(array_get($this->getAuths(), $key)); return method_exists($this, $method) ? $method : false; } return false; }
php
public function getAuthMethod($key) { if (array_has($this->getAuths(), $key)) { $method = 'auth'.studly_case(array_get($this->getAuths(), $key)); return method_exists($this, $method) ? $method : false; } return false; }
[ "public", "function", "getAuthMethod", "(", "$", "key", ")", "{", "if", "(", "array_has", "(", "$", "this", "->", "getAuths", "(", ")", ",", "$", "key", ")", ")", "{", "$", "method", "=", "'auth'", ".", "studly_case", "(", "array_get", "(", "$", "this", "->", "getAuths", "(", ")", ",", "$", "key", ")", ")", ";", "return", "method_exists", "(", "$", "this", ",", "$", "method", ")", "?", "$", "method", ":", "false", ";", "}", "return", "false", ";", "}" ]
Get auth method. @param string $key @return string|array
[ "Get", "auth", "method", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L393-L402
29,662
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.getCastToDefinition
protected function getCastToDefinition($type) { // Custom definitions. if (array_has(static::$cast_to, $type)) { return array_get(static::$cast_to, $type); } // Fallback to default. if (array_has(static::$default_cast_to, $type)) { return array_get(static::$default_cast_to, $type); } return false; }
php
protected function getCastToDefinition($type) { // Custom definitions. if (array_has(static::$cast_to, $type)) { return array_get(static::$cast_to, $type); } // Fallback to default. if (array_has(static::$default_cast_to, $type)) { return array_get(static::$default_cast_to, $type); } return false; }
[ "protected", "function", "getCastToDefinition", "(", "$", "type", ")", "{", "// Custom definitions.", "if", "(", "array_has", "(", "static", "::", "$", "cast_to", ",", "$", "type", ")", ")", "{", "return", "array_get", "(", "static", "::", "$", "cast_to", ",", "$", "type", ")", ";", "}", "// Fallback to default.", "if", "(", "array_has", "(", "static", "::", "$", "default_cast_to", ",", "$", "type", ")", ")", "{", "return", "array_get", "(", "static", "::", "$", "default_cast_to", ",", "$", "type", ")", ";", "}", "return", "false", ";", "}" ]
Get the method to cast this attribte back to it's original form. @param string $type @return string|array|bool
[ "Get", "the", "method", "to", "cast", "this", "attribte", "back", "to", "it", "s", "original", "form", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L475-L488
29,663
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.savingValidation
public function savingValidation() { global $app; $this->preValidationCast(); $this->validator = new Validator($app['translator'], $this->getDirty(), $this->getAttributeRules()); if ($this->validator->fails()) { return false; } return true; }
php
public function savingValidation() { global $app; $this->preValidationCast(); $this->validator = new Validator($app['translator'], $this->getDirty(), $this->getAttributeRules()); if ($this->validator->fails()) { return false; } return true; }
[ "public", "function", "savingValidation", "(", ")", "{", "global", "$", "app", ";", "$", "this", "->", "preValidationCast", "(", ")", ";", "$", "this", "->", "validator", "=", "new", "Validator", "(", "$", "app", "[", "'translator'", "]", ",", "$", "this", "->", "getDirty", "(", ")", ",", "$", "this", "->", "getAttributeRules", "(", ")", ")", ";", "if", "(", "$", "this", "->", "validator", "->", "fails", "(", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Validate the model before saving. @return array
[ "Validate", "the", "model", "before", "saving", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L687-L699
29,664
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.preValidationCast
private function preValidationCast() { $rules = $this->getAttributeRules(); // Check each dirty attribute. foreach ($this->getDirty() as $key => $value) { // Get the rules. $rules_array = explode('|', array_get($rules, $key, '')); // First item is always the cast type. $cast = array_get($rules_array, 0, false); // Check if the value can be nullable. $nullable = in_array('nullable', $rules_array); switch ($cast) { case 'string': $value = (string) $value; break; case 'boolean': $value = (bool) (int) $value; break; case 'integer': $value = (int) $value; break; case 'numeric': $value = (float) preg_replace('/[^0-9.-]*/', '', $value); break; } // Value is empty, let's nullify. if (empty($value) && $nullable) { $value = null; } $this->attributes[$key] = $value; } }
php
private function preValidationCast() { $rules = $this->getAttributeRules(); // Check each dirty attribute. foreach ($this->getDirty() as $key => $value) { // Get the rules. $rules_array = explode('|', array_get($rules, $key, '')); // First item is always the cast type. $cast = array_get($rules_array, 0, false); // Check if the value can be nullable. $nullable = in_array('nullable', $rules_array); switch ($cast) { case 'string': $value = (string) $value; break; case 'boolean': $value = (bool) (int) $value; break; case 'integer': $value = (int) $value; break; case 'numeric': $value = (float) preg_replace('/[^0-9.-]*/', '', $value); break; } // Value is empty, let's nullify. if (empty($value) && $nullable) { $value = null; } $this->attributes[$key] = $value; } }
[ "private", "function", "preValidationCast", "(", ")", "{", "$", "rules", "=", "$", "this", "->", "getAttributeRules", "(", ")", ";", "// Check each dirty attribute.", "foreach", "(", "$", "this", "->", "getDirty", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "// Get the rules.", "$", "rules_array", "=", "explode", "(", "'|'", ",", "array_get", "(", "$", "rules", ",", "$", "key", ",", "''", ")", ")", ";", "// First item is always the cast type.", "$", "cast", "=", "array_get", "(", "$", "rules_array", ",", "0", ",", "false", ")", ";", "// Check if the value can be nullable.", "$", "nullable", "=", "in_array", "(", "'nullable'", ",", "$", "rules_array", ")", ";", "switch", "(", "$", "cast", ")", "{", "case", "'string'", ":", "$", "value", "=", "(", "string", ")", "$", "value", ";", "break", ";", "case", "'boolean'", ":", "$", "value", "=", "(", "bool", ")", "(", "int", ")", "$", "value", ";", "break", ";", "case", "'integer'", ":", "$", "value", "=", "(", "int", ")", "$", "value", ";", "break", ";", "case", "'numeric'", ":", "$", "value", "=", "(", "float", ")", "preg_replace", "(", "'/[^0-9.-]*/'", ",", "''", ",", "$", "value", ")", ";", "break", ";", "}", "// Value is empty, let's nullify.", "if", "(", "empty", "(", "$", "value", ")", "&&", "$", "nullable", ")", "{", "$", "value", "=", "null", ";", "}", "$", "this", "->", "attributes", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}" ]
Before validating, ensure the values are correctly casted. Mostly integer or boolean values where they can be set to either. eg 1 for true. @return void
[ "Before", "validating", "ensure", "the", "values", "are", "correctly", "casted", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L709-L746
29,665
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.getAttributeRules
public function getAttributeRules() { $result = []; $attributes = $this->getAttributesFromSchema(); $casts = $this->getCasts(); $casts_back = $this->getAttributesFromSchema('cast-back', true); $rules = $this->getAttributesFromSchema('rules', true); // Build full rule for each attribute. foreach ($attributes as $key) { $result[$key] = []; } // If any casts back are configured, replace the value found in casts. // Handy if we read integer values as datetime, but save back as an integer. $casts = array_merge($casts, $casts_back); // Build full rule for each attribute. foreach ($casts as $key => $cast_type) { $cast_validator = $this->parseCastToValidator($cast_type); if (!empty($cast_validator)) { $result[$key][] = $cast_validator; } if ($this->exists) { $result[$key][] = 'sometimes'; } } // Assign specified rules. foreach ($rules as $key => $rule) { $result[$key][] = $rule; } unset($result[$this->getKeyName()]); foreach ($result as $key => $rules) { $result[$key] = implode('|', $rules); } return $result; }
php
public function getAttributeRules() { $result = []; $attributes = $this->getAttributesFromSchema(); $casts = $this->getCasts(); $casts_back = $this->getAttributesFromSchema('cast-back', true); $rules = $this->getAttributesFromSchema('rules', true); // Build full rule for each attribute. foreach ($attributes as $key) { $result[$key] = []; } // If any casts back are configured, replace the value found in casts. // Handy if we read integer values as datetime, but save back as an integer. $casts = array_merge($casts, $casts_back); // Build full rule for each attribute. foreach ($casts as $key => $cast_type) { $cast_validator = $this->parseCastToValidator($cast_type); if (!empty($cast_validator)) { $result[$key][] = $cast_validator; } if ($this->exists) { $result[$key][] = 'sometimes'; } } // Assign specified rules. foreach ($rules as $key => $rule) { $result[$key][] = $rule; } unset($result[$this->getKeyName()]); foreach ($result as $key => $rules) { $result[$key] = implode('|', $rules); } return $result; }
[ "public", "function", "getAttributeRules", "(", ")", "{", "$", "result", "=", "[", "]", ";", "$", "attributes", "=", "$", "this", "->", "getAttributesFromSchema", "(", ")", ";", "$", "casts", "=", "$", "this", "->", "getCasts", "(", ")", ";", "$", "casts_back", "=", "$", "this", "->", "getAttributesFromSchema", "(", "'cast-back'", ",", "true", ")", ";", "$", "rules", "=", "$", "this", "->", "getAttributesFromSchema", "(", "'rules'", ",", "true", ")", ";", "// Build full rule for each attribute.", "foreach", "(", "$", "attributes", "as", "$", "key", ")", "{", "$", "result", "[", "$", "key", "]", "=", "[", "]", ";", "}", "// If any casts back are configured, replace the value found in casts.", "// Handy if we read integer values as datetime, but save back as an integer.", "$", "casts", "=", "array_merge", "(", "$", "casts", ",", "$", "casts_back", ")", ";", "// Build full rule for each attribute.", "foreach", "(", "$", "casts", "as", "$", "key", "=>", "$", "cast_type", ")", "{", "$", "cast_validator", "=", "$", "this", "->", "parseCastToValidator", "(", "$", "cast_type", ")", ";", "if", "(", "!", "empty", "(", "$", "cast_validator", ")", ")", "{", "$", "result", "[", "$", "key", "]", "[", "]", "=", "$", "cast_validator", ";", "}", "if", "(", "$", "this", "->", "exists", ")", "{", "$", "result", "[", "$", "key", "]", "[", "]", "=", "'sometimes'", ";", "}", "}", "// Assign specified rules.", "foreach", "(", "$", "rules", "as", "$", "key", "=>", "$", "rule", ")", "{", "$", "result", "[", "$", "key", "]", "[", "]", "=", "$", "rule", ";", "}", "unset", "(", "$", "result", "[", "$", "this", "->", "getKeyName", "(", ")", "]", ")", ";", "foreach", "(", "$", "result", "as", "$", "key", "=>", "$", "rules", ")", "{", "$", "result", "[", "$", "key", "]", "=", "implode", "(", "'|'", ",", "$", "rules", ")", ";", "}", "return", "$", "result", ";", "}" ]
Get rules for attributes. @return array
[ "Get", "rules", "for", "attributes", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L753-L795
29,666
hnhdigital-os/laravel-model-schema
src/Concerns/HasAttributes.php
HasAttributes.parseCastToValidator
private function parseCastToValidator($type) { if (array_has(static::$cast_validation, $type)) { return array_get(static::$cast_validation, $type); } if (array_has(static::$default_cast_validation, $type)) { return array_get(static::$default_cast_validation, $type); } return $type; }
php
private function parseCastToValidator($type) { if (array_has(static::$cast_validation, $type)) { return array_get(static::$cast_validation, $type); } if (array_has(static::$default_cast_validation, $type)) { return array_get(static::$default_cast_validation, $type); } return $type; }
[ "private", "function", "parseCastToValidator", "(", "$", "type", ")", "{", "if", "(", "array_has", "(", "static", "::", "$", "cast_validation", ",", "$", "type", ")", ")", "{", "return", "array_get", "(", "static", "::", "$", "cast_validation", ",", "$", "type", ")", ";", "}", "if", "(", "array_has", "(", "static", "::", "$", "default_cast_validation", ",", "$", "type", ")", ")", "{", "return", "array_get", "(", "static", "::", "$", "default_cast_validation", ",", "$", "type", ")", ";", "}", "return", "$", "type", ";", "}" ]
Convert attribute type to validation type. @param string $type @return string
[ "Convert", "attribute", "type", "to", "validation", "type", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/HasAttributes.php#L804-L815
29,667
polyfony-inc/polyfony
Private/Polyfony/Security/Accounts.php
Accounts.createCookieSession
private function createCookieSession(string $session_signature) :bool { // store a cookie with our current session key in it return Cook::put( Conf::get('security', 'cookie'), $session_signature, true, Conf::get('security', 'session_duration') ); }
php
private function createCookieSession(string $session_signature) :bool { // store a cookie with our current session key in it return Cook::put( Conf::get('security', 'cookie'), $session_signature, true, Conf::get('security', 'session_duration') ); }
[ "private", "function", "createCookieSession", "(", "string", "$", "session_signature", ")", ":", "bool", "{", "// store a cookie with our current session key in it", "return", "Cook", "::", "put", "(", "Conf", "::", "get", "(", "'security'", ",", "'cookie'", ")", ",", "$", "session_signature", ",", "true", ",", "Conf", "::", "get", "(", "'security'", ",", "'session_duration'", ")", ")", ";", "}" ]
first part of the session opening process
[ "first", "part", "of", "the", "session", "opening", "process" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Security/Accounts.php#L99-L109
29,668
polyfony-inc/polyfony
Private/Polyfony/Security/Accounts.php
Accounts.createDatabaseSessionUntil
private function createDatabaseSessionUntil(int $expiration_date, string $session_signature) :bool { // open the session return $this->set([ 'session_expiration_date' => $expiration_date, 'session_key' => $session_signature, 'last_login_origin' => Sec::getSafeRemoteAddress(), 'last_login_agent' => Sec::getSafeUserAgent(), 'last_login_date' => time() ])->save(); }
php
private function createDatabaseSessionUntil(int $expiration_date, string $session_signature) :bool { // open the session return $this->set([ 'session_expiration_date' => $expiration_date, 'session_key' => $session_signature, 'last_login_origin' => Sec::getSafeRemoteAddress(), 'last_login_agent' => Sec::getSafeUserAgent(), 'last_login_date' => time() ])->save(); }
[ "private", "function", "createDatabaseSessionUntil", "(", "int", "$", "expiration_date", ",", "string", "$", "session_signature", ")", ":", "bool", "{", "// open the session", "return", "$", "this", "->", "set", "(", "[", "'session_expiration_date'", "=>", "$", "expiration_date", ",", "'session_key'", "=>", "$", "session_signature", ",", "'last_login_origin'", "=>", "Sec", "::", "getSafeRemoteAddress", "(", ")", ",", "'last_login_agent'", "=>", "Sec", "::", "getSafeUserAgent", "(", ")", ",", "'last_login_date'", "=>", "time", "(", ")", "]", ")", "->", "save", "(", ")", ";", "}" ]
second part of the session opening process
[ "second", "part", "of", "the", "session", "opening", "process" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Security/Accounts.php#L112-L123
29,669
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAclRule.php
WebAclRule.checkMode
static public function checkMode(int $mode) { if (!in_array($mode, array(self::NONE, self::READ, self::WRITE))) { throw new AclException('wrong mode'); } }
php
static public function checkMode(int $mode) { if (!in_array($mode, array(self::NONE, self::READ, self::WRITE))) { throw new AclException('wrong mode'); } }
[ "static", "public", "function", "checkMode", "(", "int", "$", "mode", ")", "{", "if", "(", "!", "in_array", "(", "$", "mode", ",", "array", "(", "self", "::", "NONE", ",", "self", "::", "READ", ",", "self", "::", "WRITE", ")", ")", ")", "{", "throw", "new", "AclException", "(", "'wrong mode'", ")", ";", "}", "}" ]
Checks the access mode enumaration @param int $mode WebAclRule::READ or WebAclRule::WRITE @throws AclException
[ "Checks", "the", "access", "mode", "enumaration" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAclRule.php#L73-L77
29,670
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAclRule.php
WebAclRule.makeValid
public function makeValid(): array { if ($this->isValid()) { return array($this); } $ret = array(); foreach ($this->resources as $uri => $res) { $tmp = clone($this); $tmp->uri = ''; $tmp->resources = array($uri => $res); $tmp->classes = array(); $ret[] = $tmp; } foreach ($this->classes as $class) { $tmp = clone($this); $tmp->uri = ''; $tmp->resources = array(); $tmp->classes = array($class => $class); $ret[] = $tmp; } return $ret; }
php
public function makeValid(): array { if ($this->isValid()) { return array($this); } $ret = array(); foreach ($this->resources as $uri => $res) { $tmp = clone($this); $tmp->uri = ''; $tmp->resources = array($uri => $res); $tmp->classes = array(); $ret[] = $tmp; } foreach ($this->classes as $class) { $tmp = clone($this); $tmp->uri = ''; $tmp->resources = array(); $tmp->classes = array($class => $class); $ret[] = $tmp; } return $ret; }
[ "public", "function", "makeValid", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "isValid", "(", ")", ")", "{", "return", "array", "(", "$", "this", ")", ";", "}", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "resources", "as", "$", "uri", "=>", "$", "res", ")", "{", "$", "tmp", "=", "clone", "(", "$", "this", ")", ";", "$", "tmp", "->", "uri", "=", "''", ";", "$", "tmp", "->", "resources", "=", "array", "(", "$", "uri", "=>", "$", "res", ")", ";", "$", "tmp", "->", "classes", "=", "array", "(", ")", ";", "$", "ret", "[", "]", "=", "$", "tmp", ";", "}", "foreach", "(", "$", "this", "->", "classes", "as", "$", "class", ")", "{", "$", "tmp", "=", "clone", "(", "$", "this", ")", ";", "$", "tmp", "->", "uri", "=", "''", ";", "$", "tmp", "->", "resources", "=", "array", "(", ")", ";", "$", "tmp", "->", "classes", "=", "array", "(", "$", "class", "=>", "$", "class", ")", ";", "$", "ret", "[", "]", "=", "$", "tmp", ";", "}", "return", "$", "ret", ";", "}" ]
Returns collection of WebAclRule objects each describing exactly one resource or class. @return array @see isValid()
[ "Returns", "collection", "of", "WebAclRule", "objects", "each", "describing", "exactly", "one", "resource", "or", "class", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAclRule.php#L264-L285
29,671
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAclRule.php
WebAclRule.getAclMetadata
public function getAclMetadata(): Resource { $meta = (new Graph())->resource($this->uri ? $this->uri : '.'); $meta->addType('http://www.w3.org/ns/auth/acl#Authorization'); $meta->addLiteral(RC::titleProp(), 'Fedora WebAC rule'); foreach ($this->resources as $i) { $meta->addResource('http://www.w3.org/ns/auth/acl#accessTo', $i->getUri(true)); } foreach ($this->classes as $i) { $meta->addResource('http://www.w3.org/ns/auth/acl#accessToClass', $i); } foreach ($this->roles[self::USER] as $i) { if (preg_match('|^https?://.+|', $i)) { $meta->addResource('http://www.w3.org/ns/auth/acl#agent', $i); } else { $meta->addLiteral('http://www.w3.org/ns/auth/acl#agent', $i); } } foreach ($this->roles[self::GROUP] as $i) { if (preg_match('|^https?://.+|', $i)) { $meta->addResource('http://www.w3.org/ns/auth/acl#agentClass', $i); } else { $meta->addLiteral('http://www.w3.org/ns/auth/acl#agentClass', $i); } } if ($this->mode == self::WRITE) { $meta->addResource('http://www.w3.org/ns/auth/acl#mode', 'http://www.w3.org/ns/auth/acl#Write'); } if ($this->mode >= self::READ) { $meta->addResource('http://www.w3.org/ns/auth/acl#mode', 'http://www.w3.org/ns/auth/acl#Read'); } return $meta; }
php
public function getAclMetadata(): Resource { $meta = (new Graph())->resource($this->uri ? $this->uri : '.'); $meta->addType('http://www.w3.org/ns/auth/acl#Authorization'); $meta->addLiteral(RC::titleProp(), 'Fedora WebAC rule'); foreach ($this->resources as $i) { $meta->addResource('http://www.w3.org/ns/auth/acl#accessTo', $i->getUri(true)); } foreach ($this->classes as $i) { $meta->addResource('http://www.w3.org/ns/auth/acl#accessToClass', $i); } foreach ($this->roles[self::USER] as $i) { if (preg_match('|^https?://.+|', $i)) { $meta->addResource('http://www.w3.org/ns/auth/acl#agent', $i); } else { $meta->addLiteral('http://www.w3.org/ns/auth/acl#agent', $i); } } foreach ($this->roles[self::GROUP] as $i) { if (preg_match('|^https?://.+|', $i)) { $meta->addResource('http://www.w3.org/ns/auth/acl#agentClass', $i); } else { $meta->addLiteral('http://www.w3.org/ns/auth/acl#agentClass', $i); } } if ($this->mode == self::WRITE) { $meta->addResource('http://www.w3.org/ns/auth/acl#mode', 'http://www.w3.org/ns/auth/acl#Write'); } if ($this->mode >= self::READ) { $meta->addResource('http://www.w3.org/ns/auth/acl#mode', 'http://www.w3.org/ns/auth/acl#Read'); } return $meta; }
[ "public", "function", "getAclMetadata", "(", ")", ":", "Resource", "{", "$", "meta", "=", "(", "new", "Graph", "(", ")", ")", "->", "resource", "(", "$", "this", "->", "uri", "?", "$", "this", "->", "uri", ":", "'.'", ")", ";", "$", "meta", "->", "addType", "(", "'http://www.w3.org/ns/auth/acl#Authorization'", ")", ";", "$", "meta", "->", "addLiteral", "(", "RC", "::", "titleProp", "(", ")", ",", "'Fedora WebAC rule'", ")", ";", "foreach", "(", "$", "this", "->", "resources", "as", "$", "i", ")", "{", "$", "meta", "->", "addResource", "(", "'http://www.w3.org/ns/auth/acl#accessTo'", ",", "$", "i", "->", "getUri", "(", "true", ")", ")", ";", "}", "foreach", "(", "$", "this", "->", "classes", "as", "$", "i", ")", "{", "$", "meta", "->", "addResource", "(", "'http://www.w3.org/ns/auth/acl#accessToClass'", ",", "$", "i", ")", ";", "}", "foreach", "(", "$", "this", "->", "roles", "[", "self", "::", "USER", "]", "as", "$", "i", ")", "{", "if", "(", "preg_match", "(", "'|^https?://.+|'", ",", "$", "i", ")", ")", "{", "$", "meta", "->", "addResource", "(", "'http://www.w3.org/ns/auth/acl#agent'", ",", "$", "i", ")", ";", "}", "else", "{", "$", "meta", "->", "addLiteral", "(", "'http://www.w3.org/ns/auth/acl#agent'", ",", "$", "i", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "roles", "[", "self", "::", "GROUP", "]", "as", "$", "i", ")", "{", "if", "(", "preg_match", "(", "'|^https?://.+|'", ",", "$", "i", ")", ")", "{", "$", "meta", "->", "addResource", "(", "'http://www.w3.org/ns/auth/acl#agentClass'", ",", "$", "i", ")", ";", "}", "else", "{", "$", "meta", "->", "addLiteral", "(", "'http://www.w3.org/ns/auth/acl#agentClass'", ",", "$", "i", ")", ";", "}", "}", "if", "(", "$", "this", "->", "mode", "==", "self", "::", "WRITE", ")", "{", "$", "meta", "->", "addResource", "(", "'http://www.w3.org/ns/auth/acl#mode'", ",", "'http://www.w3.org/ns/auth/acl#Write'", ")", ";", "}", "if", "(", "$", "this", "->", "mode", ">=", "self", "::", "READ", ")", "{", "$", "meta", "->", "addResource", "(", "'http://www.w3.org/ns/auth/acl#mode'", ",", "'http://www.w3.org/ns/auth/acl#Read'", ")", ";", "}", "return", "$", "meta", ";", "}" ]
Returns ACL triples. @return Resource
[ "Returns", "ACL", "triples", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAclRule.php#L291-L322
29,672
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAclRule.php
WebAclRule.save
public function save(string $location = null): FedoraResource { if ($this->uri != '') { $meta = $this->getMetadata(); $meta->merge($this->getAclMetadata(), [RC::idProp()]); $this->setMetadata($meta); $this->updateMetadata(); } else { if ($location === null) { throw new InvalidArgumentException('location parameter missing'); } $meta = $this->getAclMetadata(); $meta->addResource(RC::idProp(), 'https://id.acdh.oeaw.ac.at/acl/' . microtime(true) . rand(0, 1000)); $res = $this->fedora->createResource($meta, '', $location, 'POST'); $this->uri = $res->getUri(); $this->fedora->getCache()->delete($res); $this->fedora->getCache()->add($this); } return $this; }
php
public function save(string $location = null): FedoraResource { if ($this->uri != '') { $meta = $this->getMetadata(); $meta->merge($this->getAclMetadata(), [RC::idProp()]); $this->setMetadata($meta); $this->updateMetadata(); } else { if ($location === null) { throw new InvalidArgumentException('location parameter missing'); } $meta = $this->getAclMetadata(); $meta->addResource(RC::idProp(), 'https://id.acdh.oeaw.ac.at/acl/' . microtime(true) . rand(0, 1000)); $res = $this->fedora->createResource($meta, '', $location, 'POST'); $this->uri = $res->getUri(); $this->fedora->getCache()->delete($res); $this->fedora->getCache()->add($this); } return $this; }
[ "public", "function", "save", "(", "string", "$", "location", "=", "null", ")", ":", "FedoraResource", "{", "if", "(", "$", "this", "->", "uri", "!=", "''", ")", "{", "$", "meta", "=", "$", "this", "->", "getMetadata", "(", ")", ";", "$", "meta", "->", "merge", "(", "$", "this", "->", "getAclMetadata", "(", ")", ",", "[", "RC", "::", "idProp", "(", ")", "]", ")", ";", "$", "this", "->", "setMetadata", "(", "$", "meta", ")", ";", "$", "this", "->", "updateMetadata", "(", ")", ";", "}", "else", "{", "if", "(", "$", "location", "===", "null", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'location parameter missing'", ")", ";", "}", "$", "meta", "=", "$", "this", "->", "getAclMetadata", "(", ")", ";", "$", "meta", "->", "addResource", "(", "RC", "::", "idProp", "(", ")", ",", "'https://id.acdh.oeaw.ac.at/acl/'", ".", "microtime", "(", "true", ")", ".", "rand", "(", "0", ",", "1000", ")", ")", ";", "$", "res", "=", "$", "this", "->", "fedora", "->", "createResource", "(", "$", "meta", ",", "''", ",", "$", "location", ",", "'POST'", ")", ";", "$", "this", "->", "uri", "=", "$", "res", "->", "getUri", "(", ")", ";", "$", "this", "->", "fedora", "->", "getCache", "(", ")", "->", "delete", "(", "$", "res", ")", ";", "$", "this", "->", "fedora", "->", "getCache", "(", ")", "->", "add", "(", "$", "this", ")", ";", "}", "return", "$", "this", ";", "}" ]
Saves the ACL rule. If there is no corresponging Fedora resource, it is created as a Fedora child of a resource denpted by the `$location` parameter. @param string $location URI of the parent resource (typically an ACL collection) @return FedoraResource
[ "Saves", "the", "ACL", "rule", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAclRule.php#L333-L352
29,673
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAclRule.php
WebAclRule.delete
public function delete(bool $deep = false, bool $children = false, bool $references = false) { if ($this->uri != '') { parent::delete($deep, $children, $references); } $this->uri = ''; $this->resources = $this->classes = array(); $this->roles = array( self::USER => array(), self::GROUP => array() ); }
php
public function delete(bool $deep = false, bool $children = false, bool $references = false) { if ($this->uri != '') { parent::delete($deep, $children, $references); } $this->uri = ''; $this->resources = $this->classes = array(); $this->roles = array( self::USER => array(), self::GROUP => array() ); }
[ "public", "function", "delete", "(", "bool", "$", "deep", "=", "false", ",", "bool", "$", "children", "=", "false", ",", "bool", "$", "references", "=", "false", ")", "{", "if", "(", "$", "this", "->", "uri", "!=", "''", ")", "{", "parent", "::", "delete", "(", "$", "deep", ",", "$", "children", ",", "$", "references", ")", ";", "}", "$", "this", "->", "uri", "=", "''", ";", "$", "this", "->", "resources", "=", "$", "this", "->", "classes", "=", "array", "(", ")", ";", "$", "this", "->", "roles", "=", "array", "(", "self", "::", "USER", "=>", "array", "(", ")", ",", "self", "::", "GROUP", "=>", "array", "(", ")", ")", ";", "}" ]
Removes the ACL rule from the Fedora @param bool $deep should tombstone resource will be deleted? @param bool $children should children be removed? @param bool $references should references to the resource be removed? (applies also for children when `$children == true`)
[ "Removes", "the", "ACL", "rule", "from", "the", "Fedora" ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAclRule.php#L361-L372
29,674
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/acl/WebAclRule.php
WebAclRule.loadMetadata
protected function loadMetadata(bool $force = false) { $metaEmpty = $this->metadata == null; parent::loadMetadata($force); if ($metaEmpty || $force) { foreach ($this->metadata->allResources('http://www.w3.org/ns/auth/acl#mode') as $i) { $mode = preg_replace('#^.*(Read|Write)$#', '\\1', $i->getUri()); $dict = array('Read' => self::READ, 'Write' => self::WRITE); if (!isset($dict[$mode])) { throw new AclException('wrong mode: ' . $mode); } $this->mode = max(array($this->mode, $dict[$mode])); } foreach ($this->metadata->allResources('http://www.w3.org/ns/auth/acl#accessTo') as $i) { $uri = $this->fedora->standardizeUri($i->getUri()); $this->resources[$uri] = $this->fedora->getResourceByUri($uri); } foreach ($this->metadata->allResources('http://www.w3.org/ns/auth/acl#accessToClass') as $i) { $this->classes[$i->getUri()] = $i->getUri(); } foreach ($this->metadata->all('http://www.w3.org/ns/auth/acl#agent') as $i) { $i = (string) $i; $this->roles[self::USER][$i] = $i; } foreach ($this->metadata->all('http://www.w3.org/ns/auth/acl#agentClass') as $i) { $i = (string) $i; $this->roles[self::GROUP][$i] = $i; } } }
php
protected function loadMetadata(bool $force = false) { $metaEmpty = $this->metadata == null; parent::loadMetadata($force); if ($metaEmpty || $force) { foreach ($this->metadata->allResources('http://www.w3.org/ns/auth/acl#mode') as $i) { $mode = preg_replace('#^.*(Read|Write)$#', '\\1', $i->getUri()); $dict = array('Read' => self::READ, 'Write' => self::WRITE); if (!isset($dict[$mode])) { throw new AclException('wrong mode: ' . $mode); } $this->mode = max(array($this->mode, $dict[$mode])); } foreach ($this->metadata->allResources('http://www.w3.org/ns/auth/acl#accessTo') as $i) { $uri = $this->fedora->standardizeUri($i->getUri()); $this->resources[$uri] = $this->fedora->getResourceByUri($uri); } foreach ($this->metadata->allResources('http://www.w3.org/ns/auth/acl#accessToClass') as $i) { $this->classes[$i->getUri()] = $i->getUri(); } foreach ($this->metadata->all('http://www.w3.org/ns/auth/acl#agent') as $i) { $i = (string) $i; $this->roles[self::USER][$i] = $i; } foreach ($this->metadata->all('http://www.w3.org/ns/auth/acl#agentClass') as $i) { $i = (string) $i; $this->roles[self::GROUP][$i] = $i; } } }
[ "protected", "function", "loadMetadata", "(", "bool", "$", "force", "=", "false", ")", "{", "$", "metaEmpty", "=", "$", "this", "->", "metadata", "==", "null", ";", "parent", "::", "loadMetadata", "(", "$", "force", ")", ";", "if", "(", "$", "metaEmpty", "||", "$", "force", ")", "{", "foreach", "(", "$", "this", "->", "metadata", "->", "allResources", "(", "'http://www.w3.org/ns/auth/acl#mode'", ")", "as", "$", "i", ")", "{", "$", "mode", "=", "preg_replace", "(", "'#^.*(Read|Write)$#'", ",", "'\\\\1'", ",", "$", "i", "->", "getUri", "(", ")", ")", ";", "$", "dict", "=", "array", "(", "'Read'", "=>", "self", "::", "READ", ",", "'Write'", "=>", "self", "::", "WRITE", ")", ";", "if", "(", "!", "isset", "(", "$", "dict", "[", "$", "mode", "]", ")", ")", "{", "throw", "new", "AclException", "(", "'wrong mode: '", ".", "$", "mode", ")", ";", "}", "$", "this", "->", "mode", "=", "max", "(", "array", "(", "$", "this", "->", "mode", ",", "$", "dict", "[", "$", "mode", "]", ")", ")", ";", "}", "foreach", "(", "$", "this", "->", "metadata", "->", "allResources", "(", "'http://www.w3.org/ns/auth/acl#accessTo'", ")", "as", "$", "i", ")", "{", "$", "uri", "=", "$", "this", "->", "fedora", "->", "standardizeUri", "(", "$", "i", "->", "getUri", "(", ")", ")", ";", "$", "this", "->", "resources", "[", "$", "uri", "]", "=", "$", "this", "->", "fedora", "->", "getResourceByUri", "(", "$", "uri", ")", ";", "}", "foreach", "(", "$", "this", "->", "metadata", "->", "allResources", "(", "'http://www.w3.org/ns/auth/acl#accessToClass'", ")", "as", "$", "i", ")", "{", "$", "this", "->", "classes", "[", "$", "i", "->", "getUri", "(", ")", "]", "=", "$", "i", "->", "getUri", "(", ")", ";", "}", "foreach", "(", "$", "this", "->", "metadata", "->", "all", "(", "'http://www.w3.org/ns/auth/acl#agent'", ")", "as", "$", "i", ")", "{", "$", "i", "=", "(", "string", ")", "$", "i", ";", "$", "this", "->", "roles", "[", "self", "::", "USER", "]", "[", "$", "i", "]", "=", "$", "i", ";", "}", "foreach", "(", "$", "this", "->", "metadata", "->", "all", "(", "'http://www.w3.org/ns/auth/acl#agentClass'", ")", "as", "$", "i", ")", "{", "$", "i", "=", "(", "string", ")", "$", "i", ";", "$", "this", "->", "roles", "[", "self", "::", "GROUP", "]", "[", "$", "i", "]", "=", "$", "i", ";", "}", "}", "}" ]
Loads current metadata from the Fedora and parses read ACL triples. @param bool $force enforce fetch from Fedora (when you want to make sure metadata are in line with ones in the Fedora or e.g. reset them back to their current state in Fedora) @throws AclException
[ "Loads", "current", "metadata", "from", "the", "Fedora", "and", "parses", "read", "ACL", "triples", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/acl/WebAclRule.php#L406-L435
29,675
hnhdigital-os/laravel-model-schema
src/Concerns/GuardsAttributes.php
GuardsAttributes.getGuarded
public function getGuarded() { $guarded_create = !$this->exists ? $this->getAttributesFromSchema('guarded-create', false, true) : []; $guarded_update = $this->exists ? $this->getAttributesFromSchema('guarded-update', false, true) : []; $guarded = $this->getAttributesFromSchema('guarded', false, true); return array_merge($guarded_create, $guarded_update, $guarded); }
php
public function getGuarded() { $guarded_create = !$this->exists ? $this->getAttributesFromSchema('guarded-create', false, true) : []; $guarded_update = $this->exists ? $this->getAttributesFromSchema('guarded-update', false, true) : []; $guarded = $this->getAttributesFromSchema('guarded', false, true); return array_merge($guarded_create, $guarded_update, $guarded); }
[ "public", "function", "getGuarded", "(", ")", "{", "$", "guarded_create", "=", "!", "$", "this", "->", "exists", "?", "$", "this", "->", "getAttributesFromSchema", "(", "'guarded-create'", ",", "false", ",", "true", ")", ":", "[", "]", ";", "$", "guarded_update", "=", "$", "this", "->", "exists", "?", "$", "this", "->", "getAttributesFromSchema", "(", "'guarded-update'", ",", "false", ",", "true", ")", ":", "[", "]", ";", "$", "guarded", "=", "$", "this", "->", "getAttributesFromSchema", "(", "'guarded'", ",", "false", ",", "true", ")", ";", "return", "array_merge", "(", "$", "guarded_create", ",", "$", "guarded_update", ",", "$", "guarded", ")", ";", "}" ]
Get the guarded attributes for the model. @return array
[ "Get", "the", "guarded", "attributes", "for", "the", "model", "." ]
ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e
https://github.com/hnhdigital-os/laravel-model-schema/blob/ca0c51e9862aac43d19cf06fb8bb810d6bc7d41e/src/Concerns/GuardsAttributes.php#L36-L43
29,676
ventoviro/windwalker-core
src/Core/Event/CompositeDispatcher.php
CompositeDispatcher.setDispatchers
public function setDispatchers(array $dispatchers) { foreach ($dispatchers as $name => $dispatcher) { $this->addDispatcher($name, $dispatcher); } return $this; }
php
public function setDispatchers(array $dispatchers) { foreach ($dispatchers as $name => $dispatcher) { $this->addDispatcher($name, $dispatcher); } return $this; }
[ "public", "function", "setDispatchers", "(", "array", "$", "dispatchers", ")", "{", "foreach", "(", "$", "dispatchers", "as", "$", "name", "=>", "$", "dispatcher", ")", "{", "$", "this", "->", "addDispatcher", "(", "$", "name", ",", "$", "dispatcher", ")", ";", "}", "return", "$", "this", ";", "}" ]
Method to set property dispatchers @param \Windwalker\Event\Dispatcher[] $dispatchers @return static Return self to support chaining.
[ "Method", "to", "set", "property", "dispatchers" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Event/CompositeDispatcher.php#L239-L246
29,677
ventoviro/windwalker-core
src/Core/Security/CsrfGuard.php
CsrfGuard.validate
public function validate($justDie = false, $message = 'Invalid Token') { if (!$this->checkToken()) { if ($justDie) { exit($message); } throw new InvalidTokenException($message); } return true; }
php
public function validate($justDie = false, $message = 'Invalid Token') { if (!$this->checkToken()) { if ($justDie) { exit($message); } throw new InvalidTokenException($message); } return true; }
[ "public", "function", "validate", "(", "$", "justDie", "=", "false", ",", "$", "message", "=", "'Invalid Token'", ")", "{", "if", "(", "!", "$", "this", "->", "checkToken", "(", ")", ")", "{", "if", "(", "$", "justDie", ")", "{", "exit", "(", "$", "message", ")", ";", "}", "throw", "new", "InvalidTokenException", "(", "$", "message", ")", ";", "}", "return", "true", ";", "}" ]
Validate token or die. @param bool $justDie @param string $message @return bool
[ "Validate", "token", "or", "die", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Security/CsrfGuard.php#L81-L92
29,678
ventoviro/windwalker-core
src/Core/Security/CsrfGuard.php
CsrfGuard.input
public function input($userId = null, $attribs = []) { $attribs['type'] = 'hidden'; $attribs['name'] = $this->getFormToken($userId); $attribs['value'] = 1; return h('input', $attribs, null); }
php
public function input($userId = null, $attribs = []) { $attribs['type'] = 'hidden'; $attribs['name'] = $this->getFormToken($userId); $attribs['value'] = 1; return h('input', $attribs, null); }
[ "public", "function", "input", "(", "$", "userId", "=", "null", ",", "$", "attribs", "=", "[", "]", ")", "{", "$", "attribs", "[", "'type'", "]", "=", "'hidden'", ";", "$", "attribs", "[", "'name'", "]", "=", "$", "this", "->", "getFormToken", "(", "$", "userId", ")", ";", "$", "attribs", "[", "'value'", "]", "=", "1", ";", "return", "h", "(", "'input'", ",", "$", "attribs", ",", "null", ")", ";", "}" ]
Create token input. @param mixed $userId @param array $attribs @return HtmlElement @throws \Exception
[ "Create", "token", "input", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Security/CsrfGuard.php#L103-L110
29,679
ventoviro/windwalker-core
src/Core/Security/CsrfGuard.php
CsrfGuard.getToken
public function getToken($forceNew = false) { /** @var Session $session */ $session = $this->session; $token = $session->get(static::TOKEN_KEY); // Create a token if ($token === null || $forceNew) { $token = $this->createToken(12); $session->set(static::TOKEN_KEY, $token); } return $token; }
php
public function getToken($forceNew = false) { /** @var Session $session */ $session = $this->session; $token = $session->get(static::TOKEN_KEY); // Create a token if ($token === null || $forceNew) { $token = $this->createToken(12); $session->set(static::TOKEN_KEY, $token); } return $token; }
[ "public", "function", "getToken", "(", "$", "forceNew", "=", "false", ")", "{", "/** @var Session $session */", "$", "session", "=", "$", "this", "->", "session", ";", "$", "token", "=", "$", "session", "->", "get", "(", "static", "::", "TOKEN_KEY", ")", ";", "// Create a token", "if", "(", "$", "token", "===", "null", "||", "$", "forceNew", ")", "{", "$", "token", "=", "$", "this", "->", "createToken", "(", "12", ")", ";", "$", "session", "->", "set", "(", "static", "::", "TOKEN_KEY", ",", "$", "token", ")", ";", "}", "return", "$", "token", ";", "}" ]
Get form token string. @param boolean $forceNew Force create new token. @return string @throws \UnexpectedValueException @throws \RuntimeException @throws \Exception
[ "Get", "form", "token", "string", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Security/CsrfGuard.php#L145-L160
29,680
ventoviro/windwalker-core
src/Core/Security/CsrfGuard.php
CsrfGuard.getFormToken
public function getFormToken($userId = null, $forceNew = false) { $userId = $userId ?: $this->userManager->getUser()->id; $userId = $userId ?: $this->session->getId(); $config = $this->config; return md5($config['system.secret'] . $userId . $this->getToken($forceNew)); }
php
public function getFormToken($userId = null, $forceNew = false) { $userId = $userId ?: $this->userManager->getUser()->id; $userId = $userId ?: $this->session->getId(); $config = $this->config; return md5($config['system.secret'] . $userId . $this->getToken($forceNew)); }
[ "public", "function", "getFormToken", "(", "$", "userId", "=", "null", ",", "$", "forceNew", "=", "false", ")", "{", "$", "userId", "=", "$", "userId", "?", ":", "$", "this", "->", "userManager", "->", "getUser", "(", ")", "->", "id", ";", "$", "userId", "=", "$", "userId", "?", ":", "$", "this", "->", "session", "->", "getId", "(", ")", ";", "$", "config", "=", "$", "this", "->", "config", ";", "return", "md5", "(", "$", "config", "[", "'system.secret'", "]", ".", "$", "userId", ".", "$", "this", "->", "getToken", "(", "$", "forceNew", ")", ")", ";", "}" ]
Get a token for specific user. @param mixed $userId An identify of current user. @param boolean $forceNew Force create new token. @return string @throws \RuntimeException @throws \UnexpectedValueException @throws \Exception
[ "Get", "a", "token", "for", "specific", "user", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Security/CsrfGuard.php#L173-L181
29,681
locomotivemtl/charcoal-ui
src/Charcoal/Ui/PrioritizableTrait.php
PrioritizableTrait.setPriority
public function setPriority($priority) { if (!is_numeric($priority)) { throw new InvalidArgumentException( 'Priority must be an integer' ); } $this->priority = intval($priority); return $this; }
php
public function setPriority($priority) { if (!is_numeric($priority)) { throw new InvalidArgumentException( 'Priority must be an integer' ); } $this->priority = intval($priority); return $this; }
[ "public", "function", "setPriority", "(", "$", "priority", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "priority", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Priority must be an integer'", ")", ";", "}", "$", "this", "->", "priority", "=", "intval", "(", "$", "priority", ")", ";", "return", "$", "this", ";", "}" ]
Set the entity's priority index. @param integer $priority An index, for sorting. @throws InvalidArgumentException If the priority is not an integer. @return self
[ "Set", "the", "entity", "s", "priority", "index", "." ]
0070f35d89ea24ae93720734d261c02a10e218b6
https://github.com/locomotivemtl/charcoal-ui/blob/0070f35d89ea24ae93720734d261c02a10e218b6/src/Charcoal/Ui/PrioritizableTrait.php#L28-L38
29,682
acdh-oeaw/repo-php-util
src/acdhOeaw/fedora/dissemination/parameter/RemoveProtocol.php
RemoveProtocol.transform
public function transform(string $value): string { if (strpos($value, 'hdl.handle.net') !== false) { $value = str_replace("http://", "", $value); }else if(strpos($value, 'https') !== false) { $value = str_replace("https://", "", $value); }else { $value = str_replace("http://", "", $value); } return $value; }
php
public function transform(string $value): string { if (strpos($value, 'hdl.handle.net') !== false) { $value = str_replace("http://", "", $value); }else if(strpos($value, 'https') !== false) { $value = str_replace("https://", "", $value); }else { $value = str_replace("http://", "", $value); } return $value; }
[ "public", "function", "transform", "(", "string", "$", "value", ")", ":", "string", "{", "if", "(", "strpos", "(", "$", "value", ",", "'hdl.handle.net'", ")", "!==", "false", ")", "{", "$", "value", "=", "str_replace", "(", "\"http://\"", ",", "\"\"", ",", "$", "value", ")", ";", "}", "else", "if", "(", "strpos", "(", "$", "value", ",", "'https'", ")", "!==", "false", ")", "{", "$", "value", "=", "str_replace", "(", "\"https://\"", ",", "\"\"", ",", "$", "value", ")", ";", "}", "else", "{", "$", "value", "=", "str_replace", "(", "\"http://\"", ",", "\"\"", ",", "$", "value", ")", ";", "}", "return", "$", "value", ";", "}" ]
Returns raw URL decoded value from the acdh identifier. @param string $value value to be transformed @return string
[ "Returns", "raw", "URL", "decoded", "value", "from", "the", "acdh", "identifier", "." ]
e22c7cd2613f3c8daf0deee879896d9cd7f61b41
https://github.com/acdh-oeaw/repo-php-util/blob/e22c7cd2613f3c8daf0deee879896d9cd7f61b41/src/acdhOeaw/fedora/dissemination/parameter/RemoveProtocol.php#L52-L63
29,683
locomotivemtl/charcoal-ui
src/Charcoal/Ui/Menu/AbstractMenu.php
AbstractMenu.items
public function items(callable $itemCallback = null) { $items = $this->items; uasort($items, [ $this, 'sortItemsByPriority' ]); $itemCallback = isset($itemCallback) ? $itemCallback : $this->itemCallback; foreach ($items as $item) { if ($itemCallback) { $itemCallback($item); } $GLOBALS['widget_template'] = $item->template(); yield $item->ident() => $item; $GLOBALS['widget_template'] = ''; } }
php
public function items(callable $itemCallback = null) { $items = $this->items; uasort($items, [ $this, 'sortItemsByPriority' ]); $itemCallback = isset($itemCallback) ? $itemCallback : $this->itemCallback; foreach ($items as $item) { if ($itemCallback) { $itemCallback($item); } $GLOBALS['widget_template'] = $item->template(); yield $item->ident() => $item; $GLOBALS['widget_template'] = ''; } }
[ "public", "function", "items", "(", "callable", "$", "itemCallback", "=", "null", ")", "{", "$", "items", "=", "$", "this", "->", "items", ";", "uasort", "(", "$", "items", ",", "[", "$", "this", ",", "'sortItemsByPriority'", "]", ")", ";", "$", "itemCallback", "=", "isset", "(", "$", "itemCallback", ")", "?", "$", "itemCallback", ":", "$", "this", "->", "itemCallback", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "if", "(", "$", "itemCallback", ")", "{", "$", "itemCallback", "(", "$", "item", ")", ";", "}", "$", "GLOBALS", "[", "'widget_template'", "]", "=", "$", "item", "->", "template", "(", ")", ";", "yield", "$", "item", "->", "ident", "(", ")", "=>", "$", "item", ";", "$", "GLOBALS", "[", "'widget_template'", "]", "=", "''", ";", "}", "}" ]
Menu Item generator. @param callable $itemCallback Optional. Item callback. @return MenuItemInterface[]
[ "Menu", "Item", "generator", "." ]
0070f35d89ea24ae93720734d261c02a10e218b6
https://github.com/locomotivemtl/charcoal-ui/blob/0070f35d89ea24ae93720734d261c02a10e218b6/src/Charcoal/Ui/Menu/AbstractMenu.php#L125-L139
29,684
ventoviro/windwalker-core
src/Core/Renderer/RendererManager.php
RendererManager.getRenderer
public function getRenderer($type = self::PHP, $config = []) { $type = strtolower($type); $class = sprintf('Windwalker\Core\Renderer\%sRenderer', ucfirst($type)); if (!class_exists($class)) { $class = sprintf('Windwalker\Renderer\%sRenderer', ucfirst($type)); } if (!class_exists($class)) { throw new \DomainException(sprintf('%s renderer not supported.', $type)); } if ($type === 'blade') { if (empty($config['cache_path'])) { $config['cache_path'] = $this->config->get('path.cache') . '/renderer'; } } if ($type === 'edge') { if (empty($config['cache_path']) && !isset($config['cache'])) { $config['cache_path'] = $this->config->get('path.cache') . '/renderer'; } } if ($type === 'twig') { if (empty($config['path_separator'])) { $config['path_separator'] = '.'; } } /** @var AbstractRenderer|CoreRendererInterface|GlobalVarsTrait $renderer */ $renderer = new $class(static::getGlobalPaths(), $config); $renderer->setPackageFinder($this->finder); $renderer->setGlobals($this->getGlobals()); return $renderer; }
php
public function getRenderer($type = self::PHP, $config = []) { $type = strtolower($type); $class = sprintf('Windwalker\Core\Renderer\%sRenderer', ucfirst($type)); if (!class_exists($class)) { $class = sprintf('Windwalker\Renderer\%sRenderer', ucfirst($type)); } if (!class_exists($class)) { throw new \DomainException(sprintf('%s renderer not supported.', $type)); } if ($type === 'blade') { if (empty($config['cache_path'])) { $config['cache_path'] = $this->config->get('path.cache') . '/renderer'; } } if ($type === 'edge') { if (empty($config['cache_path']) && !isset($config['cache'])) { $config['cache_path'] = $this->config->get('path.cache') . '/renderer'; } } if ($type === 'twig') { if (empty($config['path_separator'])) { $config['path_separator'] = '.'; } } /** @var AbstractRenderer|CoreRendererInterface|GlobalVarsTrait $renderer */ $renderer = new $class(static::getGlobalPaths(), $config); $renderer->setPackageFinder($this->finder); $renderer->setGlobals($this->getGlobals()); return $renderer; }
[ "public", "function", "getRenderer", "(", "$", "type", "=", "self", "::", "PHP", ",", "$", "config", "=", "[", "]", ")", "{", "$", "type", "=", "strtolower", "(", "$", "type", ")", ";", "$", "class", "=", "sprintf", "(", "'Windwalker\\Core\\Renderer\\%sRenderer'", ",", "ucfirst", "(", "$", "type", ")", ")", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "$", "class", "=", "sprintf", "(", "'Windwalker\\Renderer\\%sRenderer'", ",", "ucfirst", "(", "$", "type", ")", ")", ";", "}", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "\\", "DomainException", "(", "sprintf", "(", "'%s renderer not supported.'", ",", "$", "type", ")", ")", ";", "}", "if", "(", "$", "type", "===", "'blade'", ")", "{", "if", "(", "empty", "(", "$", "config", "[", "'cache_path'", "]", ")", ")", "{", "$", "config", "[", "'cache_path'", "]", "=", "$", "this", "->", "config", "->", "get", "(", "'path.cache'", ")", ".", "'/renderer'", ";", "}", "}", "if", "(", "$", "type", "===", "'edge'", ")", "{", "if", "(", "empty", "(", "$", "config", "[", "'cache_path'", "]", ")", "&&", "!", "isset", "(", "$", "config", "[", "'cache'", "]", ")", ")", "{", "$", "config", "[", "'cache_path'", "]", "=", "$", "this", "->", "config", "->", "get", "(", "'path.cache'", ")", ".", "'/renderer'", ";", "}", "}", "if", "(", "$", "type", "===", "'twig'", ")", "{", "if", "(", "empty", "(", "$", "config", "[", "'path_separator'", "]", ")", ")", "{", "$", "config", "[", "'path_separator'", "]", "=", "'.'", ";", "}", "}", "/** @var AbstractRenderer|CoreRendererInterface|GlobalVarsTrait $renderer */", "$", "renderer", "=", "new", "$", "class", "(", "static", "::", "getGlobalPaths", "(", ")", ",", "$", "config", ")", ";", "$", "renderer", "->", "setPackageFinder", "(", "$", "this", "->", "finder", ")", ";", "$", "renderer", "->", "setGlobals", "(", "$", "this", "->", "getGlobals", "(", ")", ")", ";", "return", "$", "renderer", ";", "}" ]
Create a renderer object and auto inject the global paths. @param string $type Renderer engine name, php, blade, twig or mustache. @param array $config Renderer config array. @return AbstractRenderer|CoreRendererInterface @since 2.0
[ "Create", "a", "renderer", "object", "and", "auto", "inject", "the", "global", "paths", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Renderer/RendererManager.php#L97-L136
29,685
ventoviro/windwalker-core
src/Core/Renderer/RendererManager.php
RendererManager.addGlobalPath
public function addGlobalPath($path, $priority = PriorityQueue::LOW) { $this->getPaths()->insert($path, $priority); return $this; }
php
public function addGlobalPath($path, $priority = PriorityQueue::LOW) { $this->getPaths()->insert($path, $priority); return $this; }
[ "public", "function", "addGlobalPath", "(", "$", "path", ",", "$", "priority", "=", "PriorityQueue", "::", "LOW", ")", "{", "$", "this", "->", "getPaths", "(", ")", "->", "insert", "(", "$", "path", ",", "$", "priority", ")", ";", "return", "$", "this", ";", "}" ]
Add a global path for Renderer search. @param string $path The path you want to set. @param int $priority Priority flag to order paths. @return static @since 2.0
[ "Add", "a", "global", "path", "for", "Renderer", "search", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Renderer/RendererManager.php#L230-L235
29,686
ventoviro/windwalker-core
src/Core/Renderer/RendererManager.php
RendererManager.getPaths
protected function getPaths() { if (!$this->paths) { $this->paths = new PriorityQueue(); $this->registerPaths(); } return $this->paths; }
php
protected function getPaths() { if (!$this->paths) { $this->paths = new PriorityQueue(); $this->registerPaths(); } return $this->paths; }
[ "protected", "function", "getPaths", "(", ")", "{", "if", "(", "!", "$", "this", "->", "paths", ")", "{", "$", "this", "->", "paths", "=", "new", "PriorityQueue", "(", ")", ";", "$", "this", "->", "registerPaths", "(", ")", ";", "}", "return", "$", "this", "->", "paths", ";", "}" ]
Get or create paths queue. @return PriorityQueue @since 2.0
[ "Get", "or", "create", "paths", "queue", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Renderer/RendererManager.php#L261-L270
29,687
ventoviro/windwalker-core
src/Core/Renderer/RendererManager.php
RendererManager.registerPaths
protected function registerPaths() { $config = $this->config; // Priority (1) $this->addPath( realpath($config->get('path.templates')), PriorityQueue::LOW - 20 ); // Priority (2) $this->addPath( realpath(__DIR__ . '/../Resources/Templates'), PriorityQueue::LOW - 30 ); return $this; }
php
protected function registerPaths() { $config = $this->config; // Priority (1) $this->addPath( realpath($config->get('path.templates')), PriorityQueue::LOW - 20 ); // Priority (2) $this->addPath( realpath(__DIR__ . '/../Resources/Templates'), PriorityQueue::LOW - 30 ); return $this; }
[ "protected", "function", "registerPaths", "(", ")", "{", "$", "config", "=", "$", "this", "->", "config", ";", "// Priority (1)", "$", "this", "->", "addPath", "(", "realpath", "(", "$", "config", "->", "get", "(", "'path.templates'", ")", ")", ",", "PriorityQueue", "::", "LOW", "-", "20", ")", ";", "// Priority (2)", "$", "this", "->", "addPath", "(", "realpath", "(", "__DIR__", ".", "'/../Resources/Templates'", ")", ",", "PriorityQueue", "::", "LOW", "-", "30", ")", ";", "return", "$", "this", ";", "}" ]
Register default global paths. @return static @since 2.0
[ "Register", "default", "global", "paths", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Renderer/RendererManager.php#L279-L296
29,688
ventoviro/windwalker-core
src/Core/Renderer/RendererManager.php
RendererManager.setPaths
public function setPaths($paths) { if (!$paths instanceof PriorityQueue) { $paths = new PriorityQueue($paths); } $this->paths = $paths; return $this; }
php
public function setPaths($paths) { if (!$paths instanceof PriorityQueue) { $paths = new PriorityQueue($paths); } $this->paths = $paths; return $this; }
[ "public", "function", "setPaths", "(", "$", "paths", ")", "{", "if", "(", "!", "$", "paths", "instanceof", "PriorityQueue", ")", "{", "$", "paths", "=", "new", "PriorityQueue", "(", "$", "paths", ")", ";", "}", "$", "this", "->", "paths", "=", "$", "paths", ";", "return", "$", "this", ";", "}" ]
Method to set property paths @param array $paths @return static Return self to support chaining.
[ "Method", "to", "set", "property", "paths" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Renderer/RendererManager.php#L319-L328
29,689
ventoviro/windwalker-core
src/Core/Seeder/Command/SeedCommand.php
SeedCommand.init
public function init() { $this->addCommand(ImportCommand::class); $this->addCommand(ClearCommand::class); $this->addGlobalOption('c') ->alias('class') ->defaultValue('MainSeeder') ->description('The class to import.'); $this->addGlobalOption('d') ->alias('dir') ->description('The directory of this seeder.'); $this->addGlobalOption('p') ->alias('package') ->description('Package name to import seeder.'); parent::init(); }
php
public function init() { $this->addCommand(ImportCommand::class); $this->addCommand(ClearCommand::class); $this->addGlobalOption('c') ->alias('class') ->defaultValue('MainSeeder') ->description('The class to import.'); $this->addGlobalOption('d') ->alias('dir') ->description('The directory of this seeder.'); $this->addGlobalOption('p') ->alias('package') ->description('Package name to import seeder.'); parent::init(); }
[ "public", "function", "init", "(", ")", "{", "$", "this", "->", "addCommand", "(", "ImportCommand", "::", "class", ")", ";", "$", "this", "->", "addCommand", "(", "ClearCommand", "::", "class", ")", ";", "$", "this", "->", "addGlobalOption", "(", "'c'", ")", "->", "alias", "(", "'class'", ")", "->", "defaultValue", "(", "'MainSeeder'", ")", "->", "description", "(", "'The class to import.'", ")", ";", "$", "this", "->", "addGlobalOption", "(", "'d'", ")", "->", "alias", "(", "'dir'", ")", "->", "description", "(", "'The directory of this seeder.'", ")", ";", "$", "this", "->", "addGlobalOption", "(", "'p'", ")", "->", "alias", "(", "'package'", ")", "->", "description", "(", "'Package name to import seeder.'", ")", ";", "parent", "::", "init", "(", ")", ";", "}" ]
Initialise command information. @return void
[ "Initialise", "command", "information", "." ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Seeder/Command/SeedCommand.php#L60-L79
29,690
polyfony-inc/polyfony
Private/Polyfony/Filesystem.php
Filesystem.chroot
public static function chroot(string $path='/', bool $override = false) { // this is now deprecated, will probably be removed in a future release trigger_error( 'Usage of Polyfony\Filesystem is deprecated, require symfony/filesystem instead', E_USER_DEPRECATED ); // if chrooting is enabled in the configuration if(Config::get('filesystem', 'chroot') && !$override) { // if the path already has the proper (ch)root if(strpos($path, Config::get('filesystem', 'data_path')) === 0) { // remove the root, remove double dots $path = str_replace(array(Config::get('filesystem', 'data_path'), '..'), '', $path); // re-add the root return(Config::get('filesystem', 'data_path') . $path); } // the path doesn't start with the (ch)root else { // remove all double dots and add the root path return(Config::get('filesystem', 'data_path') . str_replace('..','',$path)); } } // return the path (altered or not) return($path); }
php
public static function chroot(string $path='/', bool $override = false) { // this is now deprecated, will probably be removed in a future release trigger_error( 'Usage of Polyfony\Filesystem is deprecated, require symfony/filesystem instead', E_USER_DEPRECATED ); // if chrooting is enabled in the configuration if(Config::get('filesystem', 'chroot') && !$override) { // if the path already has the proper (ch)root if(strpos($path, Config::get('filesystem', 'data_path')) === 0) { // remove the root, remove double dots $path = str_replace(array(Config::get('filesystem', 'data_path'), '..'), '', $path); // re-add the root return(Config::get('filesystem', 'data_path') . $path); } // the path doesn't start with the (ch)root else { // remove all double dots and add the root path return(Config::get('filesystem', 'data_path') . str_replace('..','',$path)); } } // return the path (altered or not) return($path); }
[ "public", "static", "function", "chroot", "(", "string", "$", "path", "=", "'/'", ",", "bool", "$", "override", "=", "false", ")", "{", "// this is now deprecated, will probably be removed in a future release", "trigger_error", "(", "'Usage of Polyfony\\Filesystem is deprecated, require symfony/filesystem instead'", ",", "E_USER_DEPRECATED", ")", ";", "// if chrooting is enabled in the configuration", "if", "(", "Config", "::", "get", "(", "'filesystem'", ",", "'chroot'", ")", "&&", "!", "$", "override", ")", "{", "// if the path already has the proper (ch)root", "if", "(", "strpos", "(", "$", "path", ",", "Config", "::", "get", "(", "'filesystem'", ",", "'data_path'", ")", ")", "===", "0", ")", "{", "// remove the root, remove double dots", "$", "path", "=", "str_replace", "(", "array", "(", "Config", "::", "get", "(", "'filesystem'", ",", "'data_path'", ")", ",", "'..'", ")", ",", "''", ",", "$", "path", ")", ";", "// re-add the root", "return", "(", "Config", "::", "get", "(", "'filesystem'", ",", "'data_path'", ")", ".", "$", "path", ")", ";", "}", "// the path doesn't start with the (ch)root", "else", "{", "// remove all double dots and add the root path", "return", "(", "Config", "::", "get", "(", "'filesystem'", ",", "'data_path'", ")", ".", "str_replace", "(", "'..'", ",", "''", ",", "$", "path", ")", ")", ";", "}", "}", "// return the path (altered or not)", "return", "(", "$", "path", ")", ";", "}" ]
this will restrict a path to the data storage folder
[ "this", "will", "restrict", "a", "path", "to", "the", "data", "storage", "folder" ]
76dac2f4141c8f480370236295c07dfa52e5c589
https://github.com/polyfony-inc/polyfony/blob/76dac2f4141c8f480370236295c07dfa52e5c589/Private/Polyfony/Filesystem.php#L14-L40
29,691
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/ProductService.php
ProductService.get
public function get($id) { if (empty($id)) { throw new \Exception('cannot load object with empty id'); } $params = new RequestParams(RequestOps::GET, $this->resourceMetadata, $id); $jsonResponse = $this->request($params); if ($jsonResponse == false) { throw new Exception('Error retrieving data'); } $inst = $this->createResourceInst($jsonResponse, $this->resourceMetadata->resourceClass); $this->postProcess($inst); return $inst; }
php
public function get($id) { if (empty($id)) { throw new \Exception('cannot load object with empty id'); } $params = new RequestParams(RequestOps::GET, $this->resourceMetadata, $id); $jsonResponse = $this->request($params); if ($jsonResponse == false) { throw new Exception('Error retrieving data'); } $inst = $this->createResourceInst($jsonResponse, $this->resourceMetadata->resourceClass); $this->postProcess($inst); return $inst; }
[ "public", "function", "get", "(", "$", "id", ")", "{", "if", "(", "empty", "(", "$", "id", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'cannot load object with empty id'", ")", ";", "}", "$", "params", "=", "new", "RequestParams", "(", "RequestOps", "::", "GET", ",", "$", "this", "->", "resourceMetadata", ",", "$", "id", ")", ";", "$", "jsonResponse", "=", "$", "this", "->", "request", "(", "$", "params", ")", ";", "if", "(", "$", "jsonResponse", "==", "false", ")", "{", "throw", "new", "Exception", "(", "'Error retrieving data'", ")", ";", "}", "$", "inst", "=", "$", "this", "->", "createResourceInst", "(", "$", "jsonResponse", ",", "$", "this", "->", "resourceMetadata", "->", "resourceClass", ")", ";", "$", "this", "->", "postProcess", "(", "$", "inst", ")", ";", "return", "$", "inst", ";", "}" ]
Method to get object identified by id @param string $id @return BaseModel @throws ApiError @throws AuthError @throws ClientError @throws GuzzleException @throws Exception
[ "Method", "to", "get", "object", "identified", "by", "id" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/ProductService.php#L226-L244
29,692
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/ProductService.php
ProductService.delete
public function delete(BaseModel $model) { if (empty($model->id)) { throw new Exception('Cannot delete object with empty primary key value'); } $params = new RequestParams(RequestOps::DELETE, $this->resourceMetadata, $model->id); $jsonResponse = $this->request($params); if ($jsonResponse == false) { throw new Exception('Error deleting data'); } $this->postProcess($jsonResponse); return $jsonResponse; }
php
public function delete(BaseModel $model) { if (empty($model->id)) { throw new Exception('Cannot delete object with empty primary key value'); } $params = new RequestParams(RequestOps::DELETE, $this->resourceMetadata, $model->id); $jsonResponse = $this->request($params); if ($jsonResponse == false) { throw new Exception('Error deleting data'); } $this->postProcess($jsonResponse); return $jsonResponse; }
[ "public", "function", "delete", "(", "BaseModel", "$", "model", ")", "{", "if", "(", "empty", "(", "$", "model", "->", "id", ")", ")", "{", "throw", "new", "Exception", "(", "'Cannot delete object with empty primary key value'", ")", ";", "}", "$", "params", "=", "new", "RequestParams", "(", "RequestOps", "::", "DELETE", ",", "$", "this", "->", "resourceMetadata", ",", "$", "model", "->", "id", ")", ";", "$", "jsonResponse", "=", "$", "this", "->", "request", "(", "$", "params", ")", ";", "if", "(", "$", "jsonResponse", "==", "false", ")", "{", "throw", "new", "Exception", "(", "'Error deleting data'", ")", ";", "}", "$", "this", "->", "postProcess", "(", "$", "jsonResponse", ")", ";", "return", "$", "jsonResponse", ";", "}" ]
Function to delete the model identified by id @param BaseModel $model @return bool @throws ApiError @throws AuthError @throws ClientError @throws GuzzleException @throws Exception @internal param string $id default null
[ "Function", "to", "delete", "the", "model", "identified", "by", "id" ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/ProductService.php#L276-L292
29,693
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/ProductService.php
ProductService.save
public function save(BaseModel $model) { if ($this->resourceMetadata->resourceClass != get_class($model)) { throw new Exception('Unable save data, data type and service must match.'); } // default add new object $method = RequestOps::CREATE; if (!empty($model->id)) { // update the existing record $method = RequestOps::UPDATE; } $params = new RequestParams($method, $this->resourceMetadata, $model->id, null, null, null, MapperUtil::jsonEncode($model, $model->jsonFilterProperties(), $model->jsonFilterNullProperties())); $jsonResponse = $this->request($params); if ($jsonResponse === false) { throw new Exception('Error updating model'); } $inst = $this->createResourceInst($jsonResponse, $this->resourceMetadata->resourceClass); $this->postProcess($inst); return $inst; }
php
public function save(BaseModel $model) { if ($this->resourceMetadata->resourceClass != get_class($model)) { throw new Exception('Unable save data, data type and service must match.'); } // default add new object $method = RequestOps::CREATE; if (!empty($model->id)) { // update the existing record $method = RequestOps::UPDATE; } $params = new RequestParams($method, $this->resourceMetadata, $model->id, null, null, null, MapperUtil::jsonEncode($model, $model->jsonFilterProperties(), $model->jsonFilterNullProperties())); $jsonResponse = $this->request($params); if ($jsonResponse === false) { throw new Exception('Error updating model'); } $inst = $this->createResourceInst($jsonResponse, $this->resourceMetadata->resourceClass); $this->postProcess($inst); return $inst; }
[ "public", "function", "save", "(", "BaseModel", "$", "model", ")", "{", "if", "(", "$", "this", "->", "resourceMetadata", "->", "resourceClass", "!=", "get_class", "(", "$", "model", ")", ")", "{", "throw", "new", "Exception", "(", "'Unable save data, data type and service must match.'", ")", ";", "}", "// default add new object", "$", "method", "=", "RequestOps", "::", "CREATE", ";", "if", "(", "!", "empty", "(", "$", "model", "->", "id", ")", ")", "{", "// update the existing record", "$", "method", "=", "RequestOps", "::", "UPDATE", ";", "}", "$", "params", "=", "new", "RequestParams", "(", "$", "method", ",", "$", "this", "->", "resourceMetadata", ",", "$", "model", "->", "id", ",", "null", ",", "null", ",", "null", ",", "MapperUtil", "::", "jsonEncode", "(", "$", "model", ",", "$", "model", "->", "jsonFilterProperties", "(", ")", ",", "$", "model", "->", "jsonFilterNullProperties", "(", ")", ")", ")", ";", "$", "jsonResponse", "=", "$", "this", "->", "request", "(", "$", "params", ")", ";", "if", "(", "$", "jsonResponse", "===", "false", ")", "{", "throw", "new", "Exception", "(", "'Error updating model'", ")", ";", "}", "$", "inst", "=", "$", "this", "->", "createResourceInst", "(", "$", "jsonResponse", ",", "$", "this", "->", "resourceMetadata", "->", "resourceClass", ")", ";", "$", "this", "->", "postProcess", "(", "$", "inst", ")", ";", "return", "$", "inst", ";", "}" ]
Function to save object It can update existing or create new object, if the given object has an id with value null ist will create a new object. @param BaseModel $model The object to save. @return BaseModel The created object, has same type as the given input. @throws ApiError @throws AuthError @throws ClientError @throws GuzzleException @throws Exception
[ "Function", "to", "save", "object", "It", "can", "update", "existing", "or", "create", "new", "object", "if", "the", "given", "object", "has", "an", "id", "with", "value", "null", "ist", "will", "create", "a", "new", "object", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/ProductService.php#L307-L334
29,694
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/ProductService.php
ProductService.initMediaResource
protected function initMediaResource(&$arg) { if (is_string($arg)) { $mr = new MediaResource(); $mr->setUrl($arg); } else { $mr = $arg; } $mr->setHttpClient($this->httpClient); $mr->setStore($this->storage); return $mr; }
php
protected function initMediaResource(&$arg) { if (is_string($arg)) { $mr = new MediaResource(); $mr->setUrl($arg); } else { $mr = $arg; } $mr->setHttpClient($this->httpClient); $mr->setStore($this->storage); return $mr; }
[ "protected", "function", "initMediaResource", "(", "&", "$", "arg", ")", "{", "if", "(", "is_string", "(", "$", "arg", ")", ")", "{", "$", "mr", "=", "new", "MediaResource", "(", ")", ";", "$", "mr", "->", "setUrl", "(", "$", "arg", ")", ";", "}", "else", "{", "$", "mr", "=", "$", "arg", ";", "}", "$", "mr", "->", "setHttpClient", "(", "$", "this", "->", "httpClient", ")", ";", "$", "mr", "->", "setStore", "(", "$", "this", "->", "storage", ")", ";", "return", "$", "mr", ";", "}" ]
Create new or complete a media resource object. @param MediaResource|string $arg The media resource to initialize or a url of a resource. @return MediaResource The initialized media resource instance.
[ "Create", "new", "or", "complete", "a", "media", "resource", "object", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/ProductService.php#L702-L714
29,695
ventoviro/windwalker-core
src/Core/Package/Resolver/AbstractPackageObjectResolver.php
AbstractPackageObjectResolver.getNamespaces
public static function getNamespaces() { $called = get_called_class(); if (!isset(static::$namespaces[$called])) { static::$namespaces[$called] = new PriorityQueue(); } return static::$namespaces[$called]; }
php
public static function getNamespaces() { $called = get_called_class(); if (!isset(static::$namespaces[$called])) { static::$namespaces[$called] = new PriorityQueue(); } return static::$namespaces[$called]; }
[ "public", "static", "function", "getNamespaces", "(", ")", "{", "$", "called", "=", "get_called_class", "(", ")", ";", "if", "(", "!", "isset", "(", "static", "::", "$", "namespaces", "[", "$", "called", "]", ")", ")", "{", "static", "::", "$", "namespaces", "[", "$", "called", "]", "=", "new", "PriorityQueue", "(", ")", ";", "}", "return", "static", "::", "$", "namespaces", "[", "$", "called", "]", ";", "}" ]
Method to get property Namespaces @return PriorityQueue
[ "Method", "to", "get", "property", "Namespaces" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/Package/Resolver/AbstractPackageObjectResolver.php#L171-L180
29,696
ventoviro/windwalker-core
src/Core/View/ViewModel.php
ViewModel.getRepository
public function getRepository($name = null) { $name = strtolower($name); if ($name) { if (isset($this->repositories[$name])) { return $this->repositories[$name]; } return $this->getNullRepository(); } return $this->repository ?: $this->getNullRepository(); }
php
public function getRepository($name = null) { $name = strtolower($name); if ($name) { if (isset($this->repositories[$name])) { return $this->repositories[$name]; } return $this->getNullRepository(); } return $this->repository ?: $this->getNullRepository(); }
[ "public", "function", "getRepository", "(", "$", "name", "=", "null", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "repositories", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "repositories", "[", "$", "name", "]", ";", "}", "return", "$", "this", "->", "getNullRepository", "(", ")", ";", "}", "return", "$", "this", "->", "repository", "?", ":", "$", "this", "->", "getNullRepository", "(", ")", ";", "}" ]
Method to get property Model @param string $name @return Repository
[ "Method", "to", "get", "property", "Model" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/View/ViewModel.php#L48-L61
29,697
ventoviro/windwalker-core
src/Core/View/ViewModel.php
ViewModel.getNullRepository
public function getNullRepository() { if (!$this->nullRepository) { $this->nullRepository = new Repository(); $this->nullRepository['is.null'] = true; $this->nullRepository['null'] = true; return $this->nullRepository; } return $this->nullRepository; }
php
public function getNullRepository() { if (!$this->nullRepository) { $this->nullRepository = new Repository(); $this->nullRepository['is.null'] = true; $this->nullRepository['null'] = true; return $this->nullRepository; } return $this->nullRepository; }
[ "public", "function", "getNullRepository", "(", ")", "{", "if", "(", "!", "$", "this", "->", "nullRepository", ")", "{", "$", "this", "->", "nullRepository", "=", "new", "Repository", "(", ")", ";", "$", "this", "->", "nullRepository", "[", "'is.null'", "]", "=", "true", ";", "$", "this", "->", "nullRepository", "[", "'null'", "]", "=", "true", ";", "return", "$", "this", "->", "nullRepository", ";", "}", "return", "$", "this", "->", "nullRepository", ";", "}" ]
Method to get property NullModel @return Repository
[ "Method", "to", "get", "property", "NullModel" ]
0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074
https://github.com/ventoviro/windwalker-core/blob/0ed53059fc2d5d2d9b72f0e4aeef2fdf6aac0074/src/Core/View/ViewModel.php#L258-L270
29,698
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/MediaResourceTrait.php
MediaResourceTrait.clear
public function clear() { if (empty($this->store)) { throw new ClientError('Missing store instance to use for this operation.'); } if (!empty($this->url)) { $this->store->delete($this->getKey($this->url)); } $this->cached = false; }
php
public function clear() { if (empty($this->store)) { throw new ClientError('Missing store instance to use for this operation.'); } if (!empty($this->url)) { $this->store->delete($this->getKey($this->url)); } $this->cached = false; }
[ "public", "function", "clear", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "store", ")", ")", "{", "throw", "new", "ClientError", "(", "'Missing store instance to use for this operation.'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "url", ")", ")", "{", "$", "this", "->", "store", "->", "delete", "(", "$", "this", "->", "getKey", "(", "$", "this", "->", "url", ")", ")", ";", "}", "$", "this", "->", "cached", "=", "false", ";", "}" ]
Removes this object from cache. @throws ClientError
[ "Removes", "this", "object", "from", "cache", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/MediaResourceTrait.php#L80-L91
29,699
secucard/secucard-connect-php-sdk
src/SecucardConnect/Client/MediaResourceTrait.php
MediaResourceTrait.getContents
public function getContents($cache = true) { $result = $this->downloadMe($cache); if ($cache) { $result = $this->store->get($this->getKey($this->url)); } return $result; }
php
public function getContents($cache = true) { $result = $this->downloadMe($cache); if ($cache) { $result = $this->store->get($this->getKey($this->url)); } return $result; }
[ "public", "function", "getContents", "(", "$", "cache", "=", "true", ")", "{", "$", "result", "=", "$", "this", "->", "downloadMe", "(", "$", "cache", ")", ";", "if", "(", "$", "cache", ")", "{", "$", "result", "=", "$", "this", "->", "store", "->", "get", "(", "$", "this", "->", "getKey", "(", "$", "this", "->", "url", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Return the contents of this resource as stream. @param bool $cache True if the content should be cached locally by using the storage instance passed when creating the secucard connect API client. @return StreamInterface @throws ClientError
[ "Return", "the", "contents", "of", "this", "resource", "as", "stream", "." ]
d990686095e4e02d0924fc12b9bf60140fe8efab
https://github.com/secucard/secucard-connect-php-sdk/blob/d990686095e4e02d0924fc12b9bf60140fe8efab/src/SecucardConnect/Client/MediaResourceTrait.php#L110-L118