repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
u01jmg3/ics-parser
src/ICal/ICal.php
ICal.numberOfDays
protected function numberOfDays($days, $start, $end) { $w = array(date('w', $start), date('w', $end)); $base = floor(($end - $start) / self::SECONDS_IN_A_WEEK); $sum = 0; for ($day = 0; $day < 7; ++$day) { if ($days & pow(2, $day)) { $sum += $base + (($w[0] > $w[1]) ? $w[0] <= $day || $day <= $w[1] : $w[0] <= $day && $day <= $w[1]); } } return $sum; }
php
protected function numberOfDays($days, $start, $end) { $w = array(date('w', $start), date('w', $end)); $base = floor(($end - $start) / self::SECONDS_IN_A_WEEK); $sum = 0; for ($day = 0; $day < 7; ++$day) { if ($days & pow(2, $day)) { $sum += $base + (($w[0] > $w[1]) ? $w[0] <= $day || $day <= $w[1] : $w[0] <= $day && $day <= $w[1]); } } return $sum; }
[ "protected", "function", "numberOfDays", "(", "$", "days", ",", "$", "start", ",", "$", "end", ")", "{", "$", "w", "=", "array", "(", "date", "(", "'w'", ",", "$", "start", ")", ",", "date", "(", "'w'", ",", "$", "end", ")", ")", ";", "$", "b...
Gets the number of days between a start and end date @param integer $days @param integer $start @param integer $end @return integer
[ "Gets", "the", "number", "of", "days", "between", "a", "start", "and", "end", "date" ]
cb0f8b674b381f9d99ab0c246e9f5a4e01693606
https://github.com/u01jmg3/ics-parser/blob/cb0f8b674b381f9d99ab0c246e9f5a4e01693606/src/ICal/ICal.php#L2445-L2458
train
u01jmg3/ics-parser
src/ICal/ICal.php
ICal.convertDayOrdinalToPositive
protected function convertDayOrdinalToPositive($dayNumber, $weekday, $timestamp) { $dayNumber = empty($dayNumber) ? 1 : $dayNumber; // Returns 0 when no number defined in BYDAY $dayOrdinals = $this->dayOrdinals; // We only care about negative BYDAY values if ($dayNumber >= 1) { return $dayOrdinals[$dayNumber]; } $timestamp = (is_object($timestamp)) ? $timestamp : \DateTime::createFromFormat(self::UNIX_FORMAT, $timestamp); $start = strtotime('first day of ' . $timestamp->format(self::DATE_TIME_FORMAT_PRETTY)); $end = strtotime('last day of ' . $timestamp->format(self::DATE_TIME_FORMAT_PRETTY)); // Used with pow(2, X) so pow(2, 4) is THURSDAY $weekdays = array_flip(array_keys($this->weekdays)); $numberOfDays = $this->numberOfDays(pow(2, $weekdays[$weekday]), $start, $end); // Create subset $dayOrdinals = array_slice($dayOrdinals, 0, $numberOfDays, true); // Reverse only the values $dayOrdinals = array_combine(array_keys($dayOrdinals), array_reverse(array_values($dayOrdinals))); return $dayOrdinals[$dayNumber * -1]; }
php
protected function convertDayOrdinalToPositive($dayNumber, $weekday, $timestamp) { $dayNumber = empty($dayNumber) ? 1 : $dayNumber; // Returns 0 when no number defined in BYDAY $dayOrdinals = $this->dayOrdinals; // We only care about negative BYDAY values if ($dayNumber >= 1) { return $dayOrdinals[$dayNumber]; } $timestamp = (is_object($timestamp)) ? $timestamp : \DateTime::createFromFormat(self::UNIX_FORMAT, $timestamp); $start = strtotime('first day of ' . $timestamp->format(self::DATE_TIME_FORMAT_PRETTY)); $end = strtotime('last day of ' . $timestamp->format(self::DATE_TIME_FORMAT_PRETTY)); // Used with pow(2, X) so pow(2, 4) is THURSDAY $weekdays = array_flip(array_keys($this->weekdays)); $numberOfDays = $this->numberOfDays(pow(2, $weekdays[$weekday]), $start, $end); // Create subset $dayOrdinals = array_slice($dayOrdinals, 0, $numberOfDays, true); // Reverse only the values $dayOrdinals = array_combine(array_keys($dayOrdinals), array_reverse(array_values($dayOrdinals))); return $dayOrdinals[$dayNumber * -1]; }
[ "protected", "function", "convertDayOrdinalToPositive", "(", "$", "dayNumber", ",", "$", "weekday", ",", "$", "timestamp", ")", "{", "$", "dayNumber", "=", "empty", "(", "$", "dayNumber", ")", "?", "1", ":", "$", "dayNumber", ";", "// Returns 0 when no number ...
Converts a negative day ordinal to its equivalent positive form @param integer $dayNumber @param integer $weekday @param integer|\DateTime $timestamp @return string
[ "Converts", "a", "negative", "day", "ordinal", "to", "its", "equivalent", "positive", "form" ]
cb0f8b674b381f9d99ab0c246e9f5a4e01693606
https://github.com/u01jmg3/ics-parser/blob/cb0f8b674b381f9d99ab0c246e9f5a4e01693606/src/ICal/ICal.php#L2469-L2496
train
u01jmg3/ics-parser
src/ICal/ICal.php
ICal.mb_str_replace
protected static function mb_str_replace($search, $replace, $subject, $encoding = null, &$count = 0) { if (is_array($subject)) { // Call `mb_str_replace()` for each subject in the array, recursively foreach ($subject as $key => $value) { $subject[$key] = self::mb_str_replace($search, $replace, $value, $encoding, $count); } } else { // Normalize $search and $replace so they are both arrays of the same length $searches = is_array($search) ? array_values($search) : [$search]; $replacements = is_array($replace) ? array_values($replace) : [$replace]; $replacements = array_pad($replacements, count($searches), ''); foreach ($searches as $key => $search) { if (is_null($encoding)) { $encoding = mb_detect_encoding($search, 'UTF-8', true); } $replace = $replacements[$key]; $searchLen = mb_strlen($search, $encoding); $sb = []; while (($offset = mb_strpos($subject, $search, 0, $encoding)) !== false) { $sb[] = mb_substr($subject, 0, $offset, $encoding); $subject = mb_substr($subject, $offset + $searchLen, null, $encoding); ++$count; } $sb[] = $subject; $subject = implode($replace, $sb); } } return $subject; }
php
protected static function mb_str_replace($search, $replace, $subject, $encoding = null, &$count = 0) { if (is_array($subject)) { // Call `mb_str_replace()` for each subject in the array, recursively foreach ($subject as $key => $value) { $subject[$key] = self::mb_str_replace($search, $replace, $value, $encoding, $count); } } else { // Normalize $search and $replace so they are both arrays of the same length $searches = is_array($search) ? array_values($search) : [$search]; $replacements = is_array($replace) ? array_values($replace) : [$replace]; $replacements = array_pad($replacements, count($searches), ''); foreach ($searches as $key => $search) { if (is_null($encoding)) { $encoding = mb_detect_encoding($search, 'UTF-8', true); } $replace = $replacements[$key]; $searchLen = mb_strlen($search, $encoding); $sb = []; while (($offset = mb_strpos($subject, $search, 0, $encoding)) !== false) { $sb[] = mb_substr($subject, 0, $offset, $encoding); $subject = mb_substr($subject, $offset + $searchLen, null, $encoding); ++$count; } $sb[] = $subject; $subject = implode($replace, $sb); } } return $subject; }
[ "protected", "static", "function", "mb_str_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "subject", ",", "$", "encoding", "=", "null", ",", "&", "$", "count", "=", "0", ")", "{", "if", "(", "is_array", "(", "$", "subject", ")", ")", ...
Replace all occurrences of the search string with the replacement string. Multibyte safe. @param string|array $search @param string|array $replace @param string|array $subject @param string $encoding @param integer $count @return array|string
[ "Replace", "all", "occurrences", "of", "the", "search", "string", "with", "the", "replacement", "string", ".", "Multibyte", "safe", "." ]
cb0f8b674b381f9d99ab0c246e9f5a4e01693606
https://github.com/u01jmg3/ics-parser/blob/cb0f8b674b381f9d99ab0c246e9f5a4e01693606/src/ICal/ICal.php#L2546-L2580
train
u01jmg3/ics-parser
src/ICal/ICal.php
ICal.cleanData
protected function cleanData($data) { $replacementChars = array( "\xe2\x80\x98" => "'", // ‘ "\xe2\x80\x99" => "'", // ’ "\xe2\x80\x9a" => "'", // ‚ "\xe2\x80\x9b" => "'", // ‛ "\xe2\x80\x9c" => '"', // “ "\xe2\x80\x9d" => '"', // ” "\xe2\x80\x9e" => '"', // „ "\xe2\x80\x9f" => '"', // ‟ "\xe2\x80\x93" => '-', // – "\xe2\x80\x94" => '--', // — "\xe2\x80\xa6" => '...', // … "\xc2\xa0" => ' ', ); // Replace UTF-8 characters $cleanedData = strtr($data, $replacementChars); // Replace Windows-1252 equivalents $charsToReplace = array_map(function ($code) { return $this->mb_chr($code); }, array(133, 145, 146, 147, 148, 150, 151, 194)); $cleanedData = $this->mb_str_replace($charsToReplace, $replacementChars, $cleanedData); return $cleanedData; }
php
protected function cleanData($data) { $replacementChars = array( "\xe2\x80\x98" => "'", // ‘ "\xe2\x80\x99" => "'", // ’ "\xe2\x80\x9a" => "'", // ‚ "\xe2\x80\x9b" => "'", // ‛ "\xe2\x80\x9c" => '"', // “ "\xe2\x80\x9d" => '"', // ” "\xe2\x80\x9e" => '"', // „ "\xe2\x80\x9f" => '"', // ‟ "\xe2\x80\x93" => '-', // – "\xe2\x80\x94" => '--', // — "\xe2\x80\xa6" => '...', // … "\xc2\xa0" => ' ', ); // Replace UTF-8 characters $cleanedData = strtr($data, $replacementChars); // Replace Windows-1252 equivalents $charsToReplace = array_map(function ($code) { return $this->mb_chr($code); }, array(133, 145, 146, 147, 148, 150, 151, 194)); $cleanedData = $this->mb_str_replace($charsToReplace, $replacementChars, $cleanedData); return $cleanedData; }
[ "protected", "function", "cleanData", "(", "$", "data", ")", "{", "$", "replacementChars", "=", "array", "(", "\"\\xe2\\x80\\x98\"", "=>", "\"'\"", ",", "// ‘", "\"\\xe2\\x80\\x99\"", "=>", "\"'\"", ",", "// ’", "\"\\xe2\\x80\\x9a\"", "=>", "\"'\"", ",", "// ‚",...
Replaces curly quotes and other special characters with their standard equivalents @param string $data @return string
[ "Replaces", "curly", "quotes", "and", "other", "special", "characters", "with", "their", "standard", "equivalents" ]
cb0f8b674b381f9d99ab0c246e9f5a4e01693606
https://github.com/u01jmg3/ics-parser/blob/cb0f8b674b381f9d99ab0c246e9f5a4e01693606/src/ICal/ICal.php#L2589-L2615
train
u01jmg3/ics-parser
src/ICal/ICal.php
ICal.parseExdates
public function parseExdates(array $event) { if (empty($event['EXDATE_array'])) { return array(); } else { $exdates = $event['EXDATE_array']; } $output = array(); $currentTimeZone = $this->defaultTimeZone; foreach ($exdates as $subArray) { end($subArray); $finalKey = key($subArray); foreach ($subArray as $key => $value) { if ($key === 'TZID') { $checkTimeZone = $subArray[$key]; if ($this->isValidIanaTimeZoneId($checkTimeZone)) { $currentTimeZone = $checkTimeZone; } elseif ($this->isValidCldrTimeZoneId($checkTimeZone)) { $currentTimeZone = $this->isValidCldrTimeZoneId($checkTimeZone, true); } else { $currentTimeZone = $this->defaultTimeZone; } } elseif (is_numeric($key)) { $icalDate = $subArray[$key]; if (substr($icalDate, -1) === 'Z') { $currentTimeZone = self::TIME_ZONE_UTC; } $output[] = new Carbon($icalDate, $currentTimeZone); if ($key === $finalKey) { // Reset to default $currentTimeZone = $this->defaultTimeZone; } } } } return $output; }
php
public function parseExdates(array $event) { if (empty($event['EXDATE_array'])) { return array(); } else { $exdates = $event['EXDATE_array']; } $output = array(); $currentTimeZone = $this->defaultTimeZone; foreach ($exdates as $subArray) { end($subArray); $finalKey = key($subArray); foreach ($subArray as $key => $value) { if ($key === 'TZID') { $checkTimeZone = $subArray[$key]; if ($this->isValidIanaTimeZoneId($checkTimeZone)) { $currentTimeZone = $checkTimeZone; } elseif ($this->isValidCldrTimeZoneId($checkTimeZone)) { $currentTimeZone = $this->isValidCldrTimeZoneId($checkTimeZone, true); } else { $currentTimeZone = $this->defaultTimeZone; } } elseif (is_numeric($key)) { $icalDate = $subArray[$key]; if (substr($icalDate, -1) === 'Z') { $currentTimeZone = self::TIME_ZONE_UTC; } $output[] = new Carbon($icalDate, $currentTimeZone); if ($key === $finalKey) { // Reset to default $currentTimeZone = $this->defaultTimeZone; } } } } return $output; }
[ "public", "function", "parseExdates", "(", "array", "$", "event", ")", "{", "if", "(", "empty", "(", "$", "event", "[", "'EXDATE_array'", "]", ")", ")", "{", "return", "array", "(", ")", ";", "}", "else", "{", "$", "exdates", "=", "$", "event", "["...
Parses a list of excluded dates to be applied to an Event @param array $event @return array
[ "Parses", "a", "list", "of", "excluded", "dates", "to", "be", "applied", "to", "an", "Event" ]
cb0f8b674b381f9d99ab0c246e9f5a4e01693606
https://github.com/u01jmg3/ics-parser/blob/cb0f8b674b381f9d99ab0c246e9f5a4e01693606/src/ICal/ICal.php#L2624-L2668
train
u01jmg3/ics-parser
src/ICal/ICal.php
ICal.isValidDate
public function isValidDate($value) { if (!$value) { return false; } try { new \DateTime($value); return true; } catch (\Exception $e) { return false; } }
php
public function isValidDate($value) { if (!$value) { return false; } try { new \DateTime($value); return true; } catch (\Exception $e) { return false; } }
[ "public", "function", "isValidDate", "(", "$", "value", ")", "{", "if", "(", "!", "$", "value", ")", "{", "return", "false", ";", "}", "try", "{", "new", "\\", "DateTime", "(", "$", "value", ")", ";", "return", "true", ";", "}", "catch", "(", "\\...
Checks if a date string is a valid date @param string $value @return boolean @throws \Exception
[ "Checks", "if", "a", "date", "string", "is", "a", "valid", "date" ]
cb0f8b674b381f9d99ab0c246e9f5a4e01693606
https://github.com/u01jmg3/ics-parser/blob/cb0f8b674b381f9d99ab0c246e9f5a4e01693606/src/ICal/ICal.php#L2677-L2690
train
u01jmg3/ics-parser
src/ICal/ICal.php
ICal.fileOrUrl
protected function fileOrUrl($filename) { $options = array(); if (!empty($this->httpBasicAuth) || !empty($this->httpUserAgent)) { $options['http'] = array(); $options['http']['header'] = array(); if (!empty($this->httpBasicAuth)) { $username = $this->httpBasicAuth['username']; $password = $this->httpBasicAuth['password']; $basicAuth = base64_encode("{$username}:{$password}"); array_push($options['http']['header'], "Authorization: Basic {$basicAuth}"); } if (!empty($this->httpUserAgent)) { array_push($options['http']['header'], "User-Agent: {$this->httpUserAgent}"); } } $context = stream_context_create($options); if (($lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES, $context)) === false) { throw new \Exception("The file path or URL '{$filename}' does not exist."); } return $lines; }
php
protected function fileOrUrl($filename) { $options = array(); if (!empty($this->httpBasicAuth) || !empty($this->httpUserAgent)) { $options['http'] = array(); $options['http']['header'] = array(); if (!empty($this->httpBasicAuth)) { $username = $this->httpBasicAuth['username']; $password = $this->httpBasicAuth['password']; $basicAuth = base64_encode("{$username}:{$password}"); array_push($options['http']['header'], "Authorization: Basic {$basicAuth}"); } if (!empty($this->httpUserAgent)) { array_push($options['http']['header'], "User-Agent: {$this->httpUserAgent}"); } } $context = stream_context_create($options); if (($lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES, $context)) === false) { throw new \Exception("The file path or URL '{$filename}' does not exist."); } return $lines; }
[ "protected", "function", "fileOrUrl", "(", "$", "filename", ")", "{", "$", "options", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "httpBasicAuth", ")", "||", "!", "empty", "(", "$", "this", "->", "httpUserAgent", ")"...
Reads an entire file or URL into an array @param string $filename @return array @throws \Exception
[ "Reads", "an", "entire", "file", "or", "URL", "into", "an", "array" ]
cb0f8b674b381f9d99ab0c246e9f5a4e01693606
https://github.com/u01jmg3/ics-parser/blob/cb0f8b674b381f9d99ab0c246e9f5a4e01693606/src/ICal/ICal.php#L2710-L2737
train
u01jmg3/ics-parser
src/ICal/ICal.php
ICal.trimToRecurrenceCount
protected function trimToRecurrenceCount(array $rrules, array $recurrenceEvents) { if (isset($rrules['COUNT'])) { $recurrenceCount = (intval($rrules['COUNT']) - 1); $surplusCount = (sizeof($recurrenceEvents) - $recurrenceCount); if ($surplusCount > 0) { $recurrenceEvents = array_slice($recurrenceEvents, 0, $recurrenceCount); $this->eventCount -= $surplusCount; } } return $recurrenceEvents; }
php
protected function trimToRecurrenceCount(array $rrules, array $recurrenceEvents) { if (isset($rrules['COUNT'])) { $recurrenceCount = (intval($rrules['COUNT']) - 1); $surplusCount = (sizeof($recurrenceEvents) - $recurrenceCount); if ($surplusCount > 0) { $recurrenceEvents = array_slice($recurrenceEvents, 0, $recurrenceCount); $this->eventCount -= $surplusCount; } } return $recurrenceEvents; }
[ "protected", "function", "trimToRecurrenceCount", "(", "array", "$", "rrules", ",", "array", "$", "recurrenceEvents", ")", "{", "if", "(", "isset", "(", "$", "rrules", "[", "'COUNT'", "]", ")", ")", "{", "$", "recurrenceCount", "=", "(", "intval", "(", "...
Ensures the recurrence count is enforced against generated recurrence events. @param array $rrules @param array $recurrenceEvents @return array
[ "Ensures", "the", "recurrence", "count", "is", "enforced", "against", "generated", "recurrence", "events", "." ]
cb0f8b674b381f9d99ab0c246e9f5a4e01693606
https://github.com/u01jmg3/ics-parser/blob/cb0f8b674b381f9d99ab0c246e9f5a4e01693606/src/ICal/ICal.php#L2746-L2759
train
u01jmg3/ics-parser
src/ICal/ICal.php
ICal.isExdateMatch
protected function isExdateMatch($exdate, array $anEvent, $recurringOffset) { $searchDate = $anEvent['DTSTART']; if (substr($searchDate, -1) === 'Z') { $timeZone = self::TIME_ZONE_UTC; } else { if (isset($anEvent['DTSTART_array'][0]['TZID'])) { $checkTimeZone = $anEvent['DTSTART_array'][0]['TZID']; if ($this->isValidIanaTimeZoneId($checkTimeZone)) { $timeZone = $checkTimeZone; } elseif ($this->isValidCldrTimeZoneId($checkTimeZone)) { $timeZone = $this->isValidCldrTimeZoneId($checkTimeZone, true); } else { $timeZone = $this->defaultTimeZone; } } else { $timeZone = $this->defaultTimeZone; } } $a = new Carbon($searchDate, $timeZone); $b = $exdate->addSeconds($recurringOffset); return $a->eq($b); }
php
protected function isExdateMatch($exdate, array $anEvent, $recurringOffset) { $searchDate = $anEvent['DTSTART']; if (substr($searchDate, -1) === 'Z') { $timeZone = self::TIME_ZONE_UTC; } else { if (isset($anEvent['DTSTART_array'][0]['TZID'])) { $checkTimeZone = $anEvent['DTSTART_array'][0]['TZID']; if ($this->isValidIanaTimeZoneId($checkTimeZone)) { $timeZone = $checkTimeZone; } elseif ($this->isValidCldrTimeZoneId($checkTimeZone)) { $timeZone = $this->isValidCldrTimeZoneId($checkTimeZone, true); } else { $timeZone = $this->defaultTimeZone; } } else { $timeZone = $this->defaultTimeZone; } } $a = new Carbon($searchDate, $timeZone); $b = $exdate->addSeconds($recurringOffset); return $a->eq($b); }
[ "protected", "function", "isExdateMatch", "(", "$", "exdate", ",", "array", "$", "anEvent", ",", "$", "recurringOffset", ")", "{", "$", "searchDate", "=", "$", "anEvent", "[", "'DTSTART'", "]", ";", "if", "(", "substr", "(", "$", "searchDate", ",", "-", ...
Checks if an excluded date matches a given date by reconciling time zones. @param Carbon $exdate @param array $anEvent @param integer $recurringOffset @return boolean
[ "Checks", "if", "an", "excluded", "date", "matches", "a", "given", "date", "by", "reconciling", "time", "zones", "." ]
cb0f8b674b381f9d99ab0c246e9f5a4e01693606
https://github.com/u01jmg3/ics-parser/blob/cb0f8b674b381f9d99ab0c246e9f5a4e01693606/src/ICal/ICal.php#L2769-L2795
train
basemkhirat/elasticsearch
src/ScoutEngine.php
ScoutEngine.filters
protected function filters(Builder $builder) { return collect($builder->wheres)->map(function ($value, $key) { return ['match_phrase' => [$key => $value]]; })->values()->all(); }
php
protected function filters(Builder $builder) { return collect($builder->wheres)->map(function ($value, $key) { return ['match_phrase' => [$key => $value]]; })->values()->all(); }
[ "protected", "function", "filters", "(", "Builder", "$", "builder", ")", "{", "return", "collect", "(", "$", "builder", "->", "wheres", ")", "->", "map", "(", "function", "(", "$", "value", ",", "$", "key", ")", "{", "return", "[", "'match_phrase'", "=...
Get the filter array for the query. @param Builder $builder @return array
[ "Get", "the", "filter", "array", "for", "the", "query", "." ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/ScoutEngine.php#L156-L161
train
basemkhirat/elasticsearch
src/Index.php
Index.ignore
public function ignore() { $args = func_get_args(); foreach ($args as $arg) { if (is_array($arg)) { $this->ignores = array_merge($this->ignores, $arg); } else { $this->ignores[] = $arg; } } $this->ignores = array_unique($this->ignores); return $this; }
php
public function ignore() { $args = func_get_args(); foreach ($args as $arg) { if (is_array($arg)) { $this->ignores = array_merge($this->ignores, $arg); } else { $this->ignores[] = $arg; } } $this->ignores = array_unique($this->ignores); return $this; }
[ "public", "function", "ignore", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "foreach", "(", "$", "args", "as", "$", "arg", ")", "{", "if", "(", "is_array", "(", "$", "arg", ")", ")", "{", "$", "this", "->", "ignores", "=", ...
Ignore bad HTTP requests @return $this
[ "Ignore", "bad", "HTTP", "requests" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Index.php#L98-L116
train
basemkhirat/elasticsearch
src/Connection.php
Connection.create
public static function create($config) { $clientBuilder = ClientBuilder::create(); if (!empty($config['handler'])) { $clientBuilder->setHandler($config['handler']); } $clientBuilder->setHosts($config["servers"]); $clientBuilder = self::configureLogging($clientBuilder,$config); $query = new Query($clientBuilder->build()); if (array_key_exists("index", $config) and $config["index"] != "") { $query->index($config["index"]); } return $query; }
php
public static function create($config) { $clientBuilder = ClientBuilder::create(); if (!empty($config['handler'])) { $clientBuilder->setHandler($config['handler']); } $clientBuilder->setHosts($config["servers"]); $clientBuilder = self::configureLogging($clientBuilder,$config); $query = new Query($clientBuilder->build()); if (array_key_exists("index", $config) and $config["index"] != "") { $query->index($config["index"]); } return $query; }
[ "public", "static", "function", "create", "(", "$", "config", ")", "{", "$", "clientBuilder", "=", "ClientBuilder", "::", "create", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "config", "[", "'handler'", "]", ")", ")", "{", "$", "clientBuilder", ...
Create a native connection suitable for any non-laravel or non-lumen apps any composer based frameworks @param $config @return Query
[ "Create", "a", "native", "connection", "suitable", "for", "any", "non", "-", "laravel", "or", "non", "-", "lumen", "apps", "any", "composer", "based", "frameworks" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Connection.php#L56-L76
train
basemkhirat/elasticsearch
src/Connection.php
Connection.connection
function connection($name) { // Check if connection is already loaded. if ($this->isLoaded($name)) { $this->connection = $this->connections[$name]; return $this->newQuery($name); } // Create a new connection. if (array_key_exists($name, $this->config["connections"])) { $config = $this->config["connections"][$name]; // Instantiate a new ClientBuilder $clientBuilder = ClientBuilder::create(); $clientBuilder->setHosts($config["servers"]); $clientBuilder = self::configureLogging($clientBuilder,$config); if (!empty($config['handler'])) { $clientBuilder->setHandler($config['handler']); } // Build the client object $connection = $clientBuilder->build(); $this->connection = $connection; $this->connections[$name] = $connection; return $this->newQuery($name); } $this->app->abort(500, "Invalid elasticsearch connection driver `" . $name . "`"); }
php
function connection($name) { // Check if connection is already loaded. if ($this->isLoaded($name)) { $this->connection = $this->connections[$name]; return $this->newQuery($name); } // Create a new connection. if (array_key_exists($name, $this->config["connections"])) { $config = $this->config["connections"][$name]; // Instantiate a new ClientBuilder $clientBuilder = ClientBuilder::create(); $clientBuilder->setHosts($config["servers"]); $clientBuilder = self::configureLogging($clientBuilder,$config); if (!empty($config['handler'])) { $clientBuilder->setHandler($config['handler']); } // Build the client object $connection = $clientBuilder->build(); $this->connection = $connection; $this->connections[$name] = $connection; return $this->newQuery($name); } $this->app->abort(500, "Invalid elasticsearch connection driver `" . $name . "`"); }
[ "function", "connection", "(", "$", "name", ")", "{", "// Check if connection is already loaded.", "if", "(", "$", "this", "->", "isLoaded", "(", "$", "name", ")", ")", "{", "$", "this", "->", "connection", "=", "$", "this", "->", "connections", "[", "$", ...
Create a connection for laravel or lumen frameworks @param $name @return Query
[ "Create", "a", "connection", "for", "laravel", "or", "lumen", "frameworks" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Connection.php#L84-L125
train
basemkhirat/elasticsearch
src/Connection.php
Connection.newQuery
function newQuery($connection) { $config = $this->config["connections"][$connection]; $query = new Query($this->connections[$connection]); if (array_key_exists("index", $config) and $config["index"] != "") { $query->index($config["index"]); } return $query; }
php
function newQuery($connection) { $config = $this->config["connections"][$connection]; $query = new Query($this->connections[$connection]); if (array_key_exists("index", $config) and $config["index"] != "") { $query->index($config["index"]); } return $query; }
[ "function", "newQuery", "(", "$", "connection", ")", "{", "$", "config", "=", "$", "this", "->", "config", "[", "\"connections\"", "]", "[", "$", "connection", "]", ";", "$", "query", "=", "new", "Query", "(", "$", "this", "->", "connections", "[", "...
route the request to the query class @param $connection @return Query
[ "route", "the", "request", "to", "the", "query", "class" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Connection.php#L148-L160
train
basemkhirat/elasticsearch
src/Request.php
Request.url
public static function url() { $server = $_SERVER; $ssl = (!empty($server['HTTPS']) && $server['HTTPS'] == 'on'); $sp = strtolower($server['SERVER_PROTOCOL']); $protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : ''); $port = $server['SERVER_PORT']; $port = ((!$ssl && $port == '80') || ($ssl && $port == '443')) ? '' : ':' . $port; $host = isset($host) ? $host : $server['SERVER_NAME'] . $port; $host .= preg_replace("/\?.*/", "", $server["REQUEST_URI"]); return $protocol . '://' . $host; }
php
public static function url() { $server = $_SERVER; $ssl = (!empty($server['HTTPS']) && $server['HTTPS'] == 'on'); $sp = strtolower($server['SERVER_PROTOCOL']); $protocol = substr($sp, 0, strpos($sp, '/')) . (($ssl) ? 's' : ''); $port = $server['SERVER_PORT']; $port = ((!$ssl && $port == '80') || ($ssl && $port == '443')) ? '' : ':' . $port; $host = isset($host) ? $host : $server['SERVER_NAME'] . $port; $host .= preg_replace("/\?.*/", "", $server["REQUEST_URI"]); return $protocol . '://' . $host; }
[ "public", "static", "function", "url", "(", ")", "{", "$", "server", "=", "$", "_SERVER", ";", "$", "ssl", "=", "(", "!", "empty", "(", "$", "server", "[", "'HTTPS'", "]", ")", "&&", "$", "server", "[", "'HTTPS'", "]", "==", "'on'", ")", ";", "...
Get the request url @return string
[ "Get", "the", "request", "url" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Request.php#L16-L36
train
basemkhirat/elasticsearch
src/Request.php
Request.get
public static function get($name, $value = NULL) { return isset($_GET[$name]) ? $_GET[$name] : $value; }
php
public static function get($name, $value = NULL) { return isset($_GET[$name]) ? $_GET[$name] : $value; }
[ "public", "static", "function", "get", "(", "$", "name", ",", "$", "value", "=", "NULL", ")", "{", "return", "isset", "(", "$", "_GET", "[", "$", "name", "]", ")", "?", "$", "_GET", "[", "$", "name", "]", ":", "$", "value", ";", "}" ]
Get value of query string parameter @param $name @param null $value @return null
[ "Get", "value", "of", "query", "string", "parameter" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Request.php#L53-L56
train
basemkhirat/elasticsearch
src/Model.php
Model.getOriginalAttribute
protected function getOriginalAttribute($name) { $method = "get" . ucfirst(camel_case($name)) . "Attribute"; $value = method_exists($this, $method) ? $this->$method($this->attributes[$name]) : $this->attributes[$name]; return $this->setAttributeType($name, $value); }
php
protected function getOriginalAttribute($name) { $method = "get" . ucfirst(camel_case($name)) . "Attribute"; $value = method_exists($this, $method) ? $this->$method($this->attributes[$name]) : $this->attributes[$name]; return $this->setAttributeType($name, $value); }
[ "protected", "function", "getOriginalAttribute", "(", "$", "name", ")", "{", "$", "method", "=", "\"get\"", ".", "ucfirst", "(", "camel_case", "(", "$", "name", ")", ")", ".", "\"Attribute\"", ";", "$", "value", "=", "method_exists", "(", "$", "this", ",...
Get original model attribute @param $name @return mixed
[ "Get", "original", "model", "attribute" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Model.php#L180-L185
train
basemkhirat/elasticsearch
src/Model.php
Model.getAppendsAttribute
protected function getAppendsAttribute($name) { $method = "get" . ucfirst(camel_case($name)) . "Attribute"; $value = method_exists($this, $method) ? $this->$method(NULL) : NULL; return $this->setAttributeType($name, $value); }
php
protected function getAppendsAttribute($name) { $method = "get" . ucfirst(camel_case($name)) . "Attribute"; $value = method_exists($this, $method) ? $this->$method(NULL) : NULL; return $this->setAttributeType($name, $value); }
[ "protected", "function", "getAppendsAttribute", "(", "$", "name", ")", "{", "$", "method", "=", "\"get\"", ".", "ucfirst", "(", "camel_case", "(", "$", "name", ")", ")", ".", "\"Attribute\"", ";", "$", "value", "=", "method_exists", "(", "$", "this", ","...
Get Appends model attribute @param $name @return mixed
[ "Get", "Appends", "model", "attribute" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Model.php#L192-L197
train
basemkhirat/elasticsearch
src/Model.php
Model.setAttributeType
protected function setAttributeType($name, $value) { if (array_key_exists($name, $this->casts)) { if (in_array($this->casts[$name], $this->castTypes)) { settype($value, $this->casts[$name]); } } return $value; }
php
protected function setAttributeType($name, $value) { if (array_key_exists($name, $this->casts)) { if (in_array($this->casts[$name], $this->castTypes)) { settype($value, $this->casts[$name]); } } return $value; }
[ "protected", "function", "setAttributeType", "(", "$", "name", ",", "$", "value", ")", "{", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "casts", ")", ")", "{", "if", "(", "in_array", "(", "$", "this", "->", "casts", "[", ...
Set attributes casting @param $name @param $value @return mixed
[ "Set", "attributes", "casting" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Model.php#L205-L215
train
basemkhirat/elasticsearch
src/Model.php
Model.toArray
public function toArray() { $attributes = []; foreach ($this->attributes as $name => $value) { $attributes[$name] = $this->getOriginalAttribute($name); } foreach ($this->appends as $name) { $attributes[$name] = $this->getAppendsAttribute($name); } return $attributes; }
php
public function toArray() { $attributes = []; foreach ($this->attributes as $name => $value) { $attributes[$name] = $this->getOriginalAttribute($name); } foreach ($this->appends as $name) { $attributes[$name] = $this->getAppendsAttribute($name); } return $attributes; }
[ "public", "function", "toArray", "(", ")", "{", "$", "attributes", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "attributes", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "attributes", "[", "$", "name", "]", "=", "$", "this", "...
Get model as array @return array
[ "Get", "model", "as", "array" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Model.php#L221-L235
train
basemkhirat/elasticsearch
src/Model.php
Model.newQuery
protected function newQuery() { $query = app("es")->setModel($this); $query->connection($this->getConnection()); if ($index = $this->getIndex()) { $query->index($index); } if ($type = $this->getType()) { $query->type($type); } return $query; }
php
protected function newQuery() { $query = app("es")->setModel($this); $query->connection($this->getConnection()); if ($index = $this->getIndex()) { $query->index($index); } if ($type = $this->getType()) { $query->type($type); } return $query; }
[ "protected", "function", "newQuery", "(", ")", "{", "$", "query", "=", "app", "(", "\"es\"", ")", "->", "setModel", "(", "$", "this", ")", ";", "$", "query", "->", "connection", "(", "$", "this", "->", "getConnection", "(", ")", ")", ";", "if", "("...
Create a new model query @return mixed
[ "Create", "a", "new", "model", "query" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Model.php#L275-L290
train
basemkhirat/elasticsearch
src/Model.php
Model.find
public static function find($key) { $instance = new static; $model = $instance->newQuery()->id($key)->take(1)->first(); if ($model) { $model->exists = true; } return $model; }
php
public static function find($key) { $instance = new static; $model = $instance->newQuery()->id($key)->take(1)->first(); if ($model) { $model->exists = true; } return $model; }
[ "public", "static", "function", "find", "(", "$", "key", ")", "{", "$", "instance", "=", "new", "static", ";", "$", "model", "=", "$", "instance", "->", "newQuery", "(", ")", "->", "id", "(", "$", "key", ")", "->", "take", "(", "1", ")", "->", ...
Get model by key @param $key @return mixed
[ "Get", "model", "by", "key" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Model.php#L310-L321
train
basemkhirat/elasticsearch
src/Model.php
Model.delete
function delete() { if (!$this->exists()) { return false; } $this->newQuery()->id($this->getID())->delete(); $this->exists = false; return $this; }
php
function delete() { if (!$this->exists()) { return false; } $this->newQuery()->id($this->getID())->delete(); $this->exists = false; return $this; }
[ "function", "delete", "(", ")", "{", "if", "(", "!", "$", "this", "->", "exists", "(", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "newQuery", "(", ")", "->", "id", "(", "$", "this", "->", "getID", "(", ")", ")", "->", "del...
Delete model record @return $this|bool
[ "Delete", "model", "record" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Model.php#L327-L339
train
basemkhirat/elasticsearch
src/Model.php
Model.save
public function save() { $fields = array_except($this->attributes, ["_index", "_type", "_id", "_score"]); if ($this->exists()) { // Update the current document $this->newQuery()->id($this->getID())->update($fields); } else { // Check if model key exists in items if (array_key_exists("_id", $this->attributes)) { $created = $this->newQuery()->id($this->attributes["_id"])->insert($fields); $this->_id = $this->attributes["_id"]; } else { $created = $this->newQuery()->insert($fields); $this->_id = $created->_id; } $this->setConnection($this->getConnection()); $this->setIndex($created->_index); // Match earlier versions $this->_index = $created->_index; $this->_type = $this->type; $this->exists = true; } return $this; }
php
public function save() { $fields = array_except($this->attributes, ["_index", "_type", "_id", "_score"]); if ($this->exists()) { // Update the current document $this->newQuery()->id($this->getID())->update($fields); } else { // Check if model key exists in items if (array_key_exists("_id", $this->attributes)) { $created = $this->newQuery()->id($this->attributes["_id"])->insert($fields); $this->_id = $this->attributes["_id"]; } else { $created = $this->newQuery()->insert($fields); $this->_id = $created->_id; } $this->setConnection($this->getConnection()); $this->setIndex($created->_index); // Match earlier versions $this->_index = $created->_index; $this->_type = $this->type; $this->exists = true; } return $this; }
[ "public", "function", "save", "(", ")", "{", "$", "fields", "=", "array_except", "(", "$", "this", "->", "attributes", ",", "[", "\"_index\"", ",", "\"_type\"", ",", "\"_id\"", ",", "\"_score\"", "]", ")", ";", "if", "(", "$", "this", "->", "exists", ...
Save data to model @return string
[ "Save", "data", "to", "model" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Model.php#L345-L380
train
basemkhirat/elasticsearch
src/Classes/Search.php
Search.fields
public function fields($fields = []) { $searchable = []; foreach ($fields as $field => $weight) { $weight_suffix = $weight > 1 ? "^$weight" : ""; $searchable[] = $field . $weight_suffix; } $this->fields = $searchable; return $this; }
php
public function fields($fields = []) { $searchable = []; foreach ($fields as $field => $weight) { $weight_suffix = $weight > 1 ? "^$weight" : ""; $searchable[] = $field . $weight_suffix; } $this->fields = $searchable; return $this; }
[ "public", "function", "fields", "(", "$", "fields", "=", "[", "]", ")", "{", "$", "searchable", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "field", "=>", "$", "weight", ")", "{", "$", "weight_suffix", "=", "$", "weight", ">", "...
Set searchable fields @param array $fields @return $this
[ "Set", "searchable", "fields" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Classes/Search.php#L59-L72
train
basemkhirat/elasticsearch
src/Classes/Search.php
Search.build
public function build() { $query_params = []; $query_params["query"] = $this->q; if($this->boost > 1) { $query_params["boost"] = $this->boost; } if(count($this->fields)){ $query_params["fields"] = $this->fields; } $this->query->must[] = [ "query_string" => $query_params ]; }
php
public function build() { $query_params = []; $query_params["query"] = $this->q; if($this->boost > 1) { $query_params["boost"] = $this->boost; } if(count($this->fields)){ $query_params["fields"] = $this->fields; } $this->query->must[] = [ "query_string" => $query_params ]; }
[ "public", "function", "build", "(", ")", "{", "$", "query_params", "=", "[", "]", ";", "$", "query_params", "[", "\"query\"", "]", "=", "$", "this", "->", "q", ";", "if", "(", "$", "this", "->", "boost", ">", "1", ")", "{", "$", "query_params", "...
Build the native query
[ "Build", "the", "native", "query" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Classes/Search.php#L89-L107
train
basemkhirat/elasticsearch
src/Commands/ReindexCommand.php
ReindexCommand.migrate
function migrate($original_index, $new_index, $scroll_id = null, $errors = 0, $page = 1) { if ($page == 1) { $pages = (int)ceil($this->es->connection($this->connection)->index($original_index)->count() / $this->size); $this->output->progressStart($pages); $documents = $this->es->connection($this->connection)->index($original_index)->type("") ->scroll($this->scroll) ->take($this->size) ->response(); } else { $documents = $this->es->connection($this->connection)->index($original_index)->type("") ->scroll($this->scroll) ->scrollID($scroll_id) ->response(); } if (isset($documents["hits"]["hits"]) and count($documents["hits"]["hits"])) { $data = $documents["hits"]["hits"]; $params = []; foreach ($data as $row) { $params["body"][] = [ 'index' => [ '_index' => $new_index, '_type' => $row["_type"], '_id' => $row["_id"] ] ]; $params["body"][] = $row["_source"]; } $response = $this->es->connection($this->connection)->raw()->bulk($params); if (isset($response["errors"]) and $response["errors"]) { if (!$this->option("hide-errors")) { if ($this->option("skip-errors")) { $this->warn("\n" . json_encode($response["items"])); } else { return $this->warn("\n" . json_encode($response["items"])); } } $errors++; } $this->output->progressAdvance(); } else { // Reindexing finished $this->output->progressFinish(); $total = $this->es->connection($this->connection)->index($original_index)->count(); if ($errors > 0) { return $this->warn("$total documents reindexed with $errors errors."); } else { return $this->info("$total documents reindexed $errors errors."); } } $page++; $this->migrate($original_index, $new_index, $documents["_scroll_id"], $errors, $page); }
php
function migrate($original_index, $new_index, $scroll_id = null, $errors = 0, $page = 1) { if ($page == 1) { $pages = (int)ceil($this->es->connection($this->connection)->index($original_index)->count() / $this->size); $this->output->progressStart($pages); $documents = $this->es->connection($this->connection)->index($original_index)->type("") ->scroll($this->scroll) ->take($this->size) ->response(); } else { $documents = $this->es->connection($this->connection)->index($original_index)->type("") ->scroll($this->scroll) ->scrollID($scroll_id) ->response(); } if (isset($documents["hits"]["hits"]) and count($documents["hits"]["hits"])) { $data = $documents["hits"]["hits"]; $params = []; foreach ($data as $row) { $params["body"][] = [ 'index' => [ '_index' => $new_index, '_type' => $row["_type"], '_id' => $row["_id"] ] ]; $params["body"][] = $row["_source"]; } $response = $this->es->connection($this->connection)->raw()->bulk($params); if (isset($response["errors"]) and $response["errors"]) { if (!$this->option("hide-errors")) { if ($this->option("skip-errors")) { $this->warn("\n" . json_encode($response["items"])); } else { return $this->warn("\n" . json_encode($response["items"])); } } $errors++; } $this->output->progressAdvance(); } else { // Reindexing finished $this->output->progressFinish(); $total = $this->es->connection($this->connection)->index($original_index)->count(); if ($errors > 0) { return $this->warn("$total documents reindexed with $errors errors."); } else { return $this->info("$total documents reindexed $errors errors."); } } $page++; $this->migrate($original_index, $new_index, $documents["_scroll_id"], $errors, $page); }
[ "function", "migrate", "(", "$", "original_index", ",", "$", "new_index", ",", "$", "scroll_id", "=", "null", ",", "$", "errors", "=", "0", ",", "$", "page", "=", "1", ")", "{", "if", "(", "$", "page", "==", "1", ")", "{", "$", "pages", "=", "(...
Migrate data with Scroll queries & Bulk API @param $original_index @param $new_index @param null $scroll_id @param int $errors @param int $page
[ "Migrate", "data", "with", "Scroll", "queries", "&", "Bulk", "API" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Commands/ReindexCommand.php#L109-L192
train
basemkhirat/elasticsearch
src/Query.php
Query.select
public function select() { $args = func_get_args(); foreach ($args as $arg) { if (is_array($arg)) { $this->_source = array_merge($this->_source, $arg); } else { $this->_source[] = $arg; } } return $this; }
php
public function select() { $args = func_get_args(); foreach ($args as $arg) { if (is_array($arg)) { $this->_source = array_merge($this->_source, $arg); } else { $this->_source[] = $arg; } } return $this; }
[ "public", "function", "select", "(", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "foreach", "(", "$", "args", "as", "$", "arg", ")", "{", "if", "(", "is_array", "(", "$", "arg", ")", ")", "{", "$", "this", "->", "_source", "=", ...
Set the query fields to return @return $this
[ "Set", "the", "query", "fields", "to", "return" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L382-L398
train
basemkhirat/elasticsearch
src/Query.php
Query._id
public function _id($_id = false) { $this->_id = $_id; $this->filter[] = ["term" => ["_id" => $_id]]; return $this; }
php
public function _id($_id = false) { $this->_id = $_id; $this->filter[] = ["term" => ["_id" => $_id]]; return $this; }
[ "public", "function", "_id", "(", "$", "_id", "=", "false", ")", "{", "$", "this", "->", "_id", "=", "$", "_id", ";", "$", "this", "->", "filter", "[", "]", "=", "[", "\"term\"", "=>", "[", "\"_id\"", "=>", "$", "_id", "]", "]", ";", "return", ...
Filter by _id @param bool $_id @return $this
[ "Filter", "by", "_id" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L405-L413
train
basemkhirat/elasticsearch
src/Query.php
Query.where
public function where($name, $operator = "=", $value = NULL) { if (is_callback_function($name)) { $name($this); return $this; } if (!$this->isOperator($operator)) { $value = $operator; $operator = "="; } if ($operator == "=") { if ($name == "_id") { return $this->_id($value); } $this->filter[] = ["term" => [$name => $value]]; } if ($operator == ">") { $this->filter[] = ["range" => [$name => ["gt" => $value]]]; } if ($operator == ">=") { $this->filter[] = ["range" => [$name => ["gte" => $value]]]; } if ($operator == "<") { $this->filter[] = ["range" => [$name => ["lt" => $value]]]; } if ($operator == "<=") { $this->filter[] = ["range" => [$name => ["lte" => $value]]]; } if ($operator == "like") { $this->must[] = ["match" => [$name => $value]]; } if ($operator == "exists") { $this->whereExists($name, $value); } return $this; }
php
public function where($name, $operator = "=", $value = NULL) { if (is_callback_function($name)) { $name($this); return $this; } if (!$this->isOperator($operator)) { $value = $operator; $operator = "="; } if ($operator == "=") { if ($name == "_id") { return $this->_id($value); } $this->filter[] = ["term" => [$name => $value]]; } if ($operator == ">") { $this->filter[] = ["range" => [$name => ["gt" => $value]]]; } if ($operator == ">=") { $this->filter[] = ["range" => [$name => ["gte" => $value]]]; } if ($operator == "<") { $this->filter[] = ["range" => [$name => ["lt" => $value]]]; } if ($operator == "<=") { $this->filter[] = ["range" => [$name => ["lte" => $value]]]; } if ($operator == "like") { $this->must[] = ["match" => [$name => $value]]; } if ($operator == "exists") { $this->whereExists($name, $value); } return $this; }
[ "public", "function", "where", "(", "$", "name", ",", "$", "operator", "=", "\"=\"", ",", "$", "value", "=", "NULL", ")", "{", "if", "(", "is_callback_function", "(", "$", "name", ")", ")", "{", "$", "name", "(", "$", "this", ")", ";", "return", ...
Set the query where clause @param $name @param string $operator @param null $value @return $this
[ "Set", "the", "query", "where", "clause" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L432-L479
train
basemkhirat/elasticsearch
src/Query.php
Query.whereNot
public function whereNot($name, $operator = "=", $value = NULL) { if (is_callback_function($name)) { $name($this); return $this; } if (!$this->isOperator($operator)) { $value = $operator; $operator = "="; } if ($operator == "=") { $this->must_not[] = ["term" => [$name => $value]]; } if ($operator == ">") { $this->must_not[] = ["range" => [$name => ["gt" => $value]]]; } if ($operator == ">=") { $this->must_not[] = ["range" => [$name => ["gte" => $value]]]; } if ($operator == "<") { $this->must_not[] = ["range" => [$name => ["lt" => $value]]]; } if ($operator == "<=") { $this->must_not[] = ["range" => [$name => ["lte" => $value]]]; } if ($operator == "like") { $this->must_not[] = ["match" => [$name => $value]]; } if ($operator == "exists") { $this->whereExists($name, !$value); } return $this; }
php
public function whereNot($name, $operator = "=", $value = NULL) { if (is_callback_function($name)) { $name($this); return $this; } if (!$this->isOperator($operator)) { $value = $operator; $operator = "="; } if ($operator == "=") { $this->must_not[] = ["term" => [$name => $value]]; } if ($operator == ">") { $this->must_not[] = ["range" => [$name => ["gt" => $value]]]; } if ($operator == ">=") { $this->must_not[] = ["range" => [$name => ["gte" => $value]]]; } if ($operator == "<") { $this->must_not[] = ["range" => [$name => ["lt" => $value]]]; } if ($operator == "<=") { $this->must_not[] = ["range" => [$name => ["lte" => $value]]]; } if ($operator == "like") { $this->must_not[] = ["match" => [$name => $value]]; } if ($operator == "exists") { $this->whereExists($name, !$value); } return $this; }
[ "public", "function", "whereNot", "(", "$", "name", ",", "$", "operator", "=", "\"=\"", ",", "$", "value", "=", "NULL", ")", "{", "if", "(", "is_callback_function", "(", "$", "name", ")", ")", "{", "$", "name", "(", "$", "this", ")", ";", "return",...
Set the query inverse where clause @param $name @param string $operator @param null $value @return $this
[ "Set", "the", "query", "inverse", "where", "clause" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L488-L530
train
basemkhirat/elasticsearch
src/Query.php
Query.whereBetween
public function whereBetween($name, $first_value, $last_value = null) { if (is_array($first_value) && count($first_value) == 2) { $last_value = $first_value[1]; $first_value = $first_value[0]; } $this->filter[] = ["range" => [$name => ["gte" => $first_value, "lte" => $last_value]]]; return $this; }
php
public function whereBetween($name, $first_value, $last_value = null) { if (is_array($first_value) && count($first_value) == 2) { $last_value = $first_value[1]; $first_value = $first_value[0]; } $this->filter[] = ["range" => [$name => ["gte" => $first_value, "lte" => $last_value]]]; return $this; }
[ "public", "function", "whereBetween", "(", "$", "name", ",", "$", "first_value", ",", "$", "last_value", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "first_value", ")", "&&", "count", "(", "$", "first_value", ")", "==", "2", ")", "{", "$"...
Set the query where between clause @param $name @param $first_value @param $last_value @return $this
[ "Set", "the", "query", "where", "between", "clause" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L539-L550
train
basemkhirat/elasticsearch
src/Query.php
Query.whereNotBetween
public function whereNotBetween($name, $first_value, $last_value = null) { if (is_array($first_value) && count($first_value) == 2) { $last_value = $first_value[1]; $first_value = $first_value[0]; } $this->must_not[] = ["range" => [$name => ["gte" => $first_value, "lte" => $last_value]]]; return $this; }
php
public function whereNotBetween($name, $first_value, $last_value = null) { if (is_array($first_value) && count($first_value) == 2) { $last_value = $first_value[1]; $first_value = $first_value[0]; } $this->must_not[] = ["range" => [$name => ["gte" => $first_value, "lte" => $last_value]]]; return $this; }
[ "public", "function", "whereNotBetween", "(", "$", "name", ",", "$", "first_value", ",", "$", "last_value", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "first_value", ")", "&&", "count", "(", "$", "first_value", ")", "==", "2", ")", "{", ...
Set the query where not between clause @param $name @param $first_value @param $last_value @return $this
[ "Set", "the", "query", "where", "not", "between", "clause" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L559-L570
train
basemkhirat/elasticsearch
src/Query.php
Query.whereIn
public function whereIn($name, $value = []) { if (is_callback_function($name)) { $name($this); return $this; } $this->filter[] = ["terms" => [$name => $value]]; return $this; }
php
public function whereIn($name, $value = []) { if (is_callback_function($name)) { $name($this); return $this; } $this->filter[] = ["terms" => [$name => $value]]; return $this; }
[ "public", "function", "whereIn", "(", "$", "name", ",", "$", "value", "=", "[", "]", ")", "{", "if", "(", "is_callback_function", "(", "$", "name", ")", ")", "{", "$", "name", "(", "$", "this", ")", ";", "return", "$", "this", ";", "}", "$", "t...
Set the query where in clause @param $name @param array $value @return $this
[ "Set", "the", "query", "where", "in", "clause" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L578-L589
train
basemkhirat/elasticsearch
src/Query.php
Query.whereNotIn
public function whereNotIn($name, $value = []) { if (is_callback_function($name)) { $name($this); return $this; } $this->must_not[] = ["terms" => [$name => $value]]; return $this; }
php
public function whereNotIn($name, $value = []) { if (is_callback_function($name)) { $name($this); return $this; } $this->must_not[] = ["terms" => [$name => $value]]; return $this; }
[ "public", "function", "whereNotIn", "(", "$", "name", ",", "$", "value", "=", "[", "]", ")", "{", "if", "(", "is_callback_function", "(", "$", "name", ")", ")", "{", "$", "name", "(", "$", "this", ")", ";", "return", "$", "this", ";", "}", "$", ...
Set the query where not in clause @param $name @param array $value @return $this
[ "Set", "the", "query", "where", "not", "in", "clause" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L597-L608
train
basemkhirat/elasticsearch
src/Query.php
Query.whereExists
public function whereExists($name, $exists = true) { if ($exists) { $this->must[] = ["exists" => ["field" => $name]]; } else { $this->must_not[] = ["exists" => ["field" => $name]]; } return $this; }
php
public function whereExists($name, $exists = true) { if ($exists) { $this->must[] = ["exists" => ["field" => $name]]; } else { $this->must_not[] = ["exists" => ["field" => $name]]; } return $this; }
[ "public", "function", "whereExists", "(", "$", "name", ",", "$", "exists", "=", "true", ")", "{", "if", "(", "$", "exists", ")", "{", "$", "this", "->", "must", "[", "]", "=", "[", "\"exists\"", "=>", "[", "\"field\"", "=>", "$", "name", "]", "]"...
Set the query where exists clause @param $name @param bool $exists @return $this
[ "Set", "the", "query", "where", "exists", "clause" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L617-L627
train
basemkhirat/elasticsearch
src/Query.php
Query.distance
public function distance($name, $value, $distance) { if (is_callback_function($name)) { $name($this); return $this; } $this->filter[] = [ "geo_distance" => [ $name => $value, "distance" => $distance, ] ]; return $this; }
php
public function distance($name, $value, $distance) { if (is_callback_function($name)) { $name($this); return $this; } $this->filter[] = [ "geo_distance" => [ $name => $value, "distance" => $distance, ] ]; return $this; }
[ "public", "function", "distance", "(", "$", "name", ",", "$", "value", ",", "$", "distance", ")", "{", "if", "(", "is_callback_function", "(", "$", "name", ")", ")", "{", "$", "name", "(", "$", "this", ")", ";", "return", "$", "this", ";", "}", "...
Add a condition to find documents which are some distance away from the given geo point. @see https://www.elastic.co/guide/en/elasticsearch/reference/2.4/query-dsl-geo-distance-query.html @param $name A name of the field. @param mixed $value A starting geo point which can be represented by a string "lat,lon", an object {"lat": lat, "lon": lon} or an array [lon,lat]. @param string $distance A distance from the starting geo point. It can be for example "20km". @return $this
[ "Add", "a", "condition", "to", "find", "documents", "which", "are", "some", "distance", "away", "from", "the", "given", "geo", "point", "." ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L644-L660
train
basemkhirat/elasticsearch
src/Query.php
Query.search
public function search($q = NULL, $settings = NULL) { if ($q) { $search = new Search($this, $q, $settings); if (!is_callback_function($settings)) { $search->boost($settings ? $settings : 1); } $search->build(); } return $this; }
php
public function search($q = NULL, $settings = NULL) { if ($q) { $search = new Search($this, $q, $settings); if (!is_callback_function($settings)) { $search->boost($settings ? $settings : 1); } $search->build(); } return $this; }
[ "public", "function", "search", "(", "$", "q", "=", "NULL", ",", "$", "settings", "=", "NULL", ")", "{", "if", "(", "$", "q", ")", "{", "$", "search", "=", "new", "Search", "(", "$", "this", ",", "$", "q", ",", "$", "settings", ")", ";", "if"...
Search the entire document fields @param null $q @return $this
[ "Search", "the", "entire", "document", "fields" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L667-L683
train
basemkhirat/elasticsearch
src/Query.php
Query.getBody
protected function getBody() { $body = $this->body; if (count($this->_source)) { $_source = array_key_exists("_source", $body) ? $body["_source"] : []; $body["_source"] = array_unique(array_merge($_source, $this->_source)); } if (count($this->must)) { $body["query"]["bool"]["must"] = $this->must; } if (count($this->must_not)) { $body["query"]["bool"]["must_not"] = $this->must_not; } if (count($this->filter)) { $body["query"]["bool"]["filter"] = $this->filter; } if (count($this->sort)) { $sortFields = array_key_exists("sort", $body) ? $body["sort"] : []; $body["sort"] = array_unique(array_merge($sortFields, $this->sort), SORT_REGULAR); } $this->body = $body; return $body; }
php
protected function getBody() { $body = $this->body; if (count($this->_source)) { $_source = array_key_exists("_source", $body) ? $body["_source"] : []; $body["_source"] = array_unique(array_merge($_source, $this->_source)); } if (count($this->must)) { $body["query"]["bool"]["must"] = $this->must; } if (count($this->must_not)) { $body["query"]["bool"]["must_not"] = $this->must_not; } if (count($this->filter)) { $body["query"]["bool"]["filter"] = $this->filter; } if (count($this->sort)) { $sortFields = array_key_exists("sort", $body) ? $body["sort"] : []; $body["sort"] = array_unique(array_merge($sortFields, $this->sort), SORT_REGULAR); } $this->body = $body; return $body; }
[ "protected", "function", "getBody", "(", ")", "{", "$", "body", "=", "$", "this", "->", "body", ";", "if", "(", "count", "(", "$", "this", "->", "_source", ")", ")", "{", "$", "_source", "=", "array_key_exists", "(", "\"_source\"", ",", "$", "body", ...
Generate the query body @return array
[ "Generate", "the", "query", "body" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L689-L724
train
basemkhirat/elasticsearch
src/Query.php
Query.query
public function query() { $query = []; $query["index"] = $this->getIndex(); if ($this->getType()) { $query["type"] = $this->getType(); } if ($this->model && $this->useGlobalScopes) { $this->model->boot($this); } $query["body"] = $this->getBody(); $query["from"] = $this->getSkip(); $query["size"] = $this->getTake(); if (count($this->ignores)) { $query["client"] = ['ignore' => $this->ignores]; } $search_type = $this->getSearchType(); if ($search_type) { $query["search_type"] = $search_type; } $scroll = $this->getScroll(); if ($scroll) { $query["scroll"] = $scroll; } return $query; }
php
public function query() { $query = []; $query["index"] = $this->getIndex(); if ($this->getType()) { $query["type"] = $this->getType(); } if ($this->model && $this->useGlobalScopes) { $this->model->boot($this); } $query["body"] = $this->getBody(); $query["from"] = $this->getSkip(); $query["size"] = $this->getTake(); if (count($this->ignores)) { $query["client"] = ['ignore' => $this->ignores]; } $search_type = $this->getSearchType(); if ($search_type) { $query["search_type"] = $search_type; } $scroll = $this->getScroll(); if ($scroll) { $query["scroll"] = $scroll; } return $query; }
[ "public", "function", "query", "(", ")", "{", "$", "query", "=", "[", "]", ";", "$", "query", "[", "\"index\"", "]", "=", "$", "this", "->", "getIndex", "(", ")", ";", "if", "(", "$", "this", "->", "getType", "(", ")", ")", "{", "$", "query", ...
Generate the query to be executed @return array
[ "Generate", "the", "query", "to", "be", "executed" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L743-L781
train
basemkhirat/elasticsearch
src/Query.php
Query.clear
public function clear($scroll_id = NULL) { $scroll_id = !is_null($scroll_id) ? $scroll_id : $this->scroll_id; return $this->connection->clearScroll([ "scroll_id" => $scroll_id, 'client' => ['ignore' => $this->ignores] ]); }
php
public function clear($scroll_id = NULL) { $scroll_id = !is_null($scroll_id) ? $scroll_id : $this->scroll_id; return $this->connection->clearScroll([ "scroll_id" => $scroll_id, 'client' => ['ignore' => $this->ignores] ]); }
[ "public", "function", "clear", "(", "$", "scroll_id", "=", "NULL", ")", "{", "$", "scroll_id", "=", "!", "is_null", "(", "$", "scroll_id", ")", "?", "$", "scroll_id", ":", "$", "this", "->", "scroll_id", ";", "return", "$", "this", "->", "connection", ...
Clear scroll query id @param string $scroll_id @return array|Collection
[ "Clear", "scroll", "query", "id" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L788-L797
train
basemkhirat/elasticsearch
src/Query.php
Query.get
public function get($scroll_id = NULL) { $scroll_id = NULL; $result = $this->getResult($scroll_id); return $this->getAll($result); }
php
public function get($scroll_id = NULL) { $scroll_id = NULL; $result = $this->getResult($scroll_id); return $this->getAll($result); }
[ "public", "function", "get", "(", "$", "scroll_id", "=", "NULL", ")", "{", "$", "scroll_id", "=", "NULL", ";", "$", "result", "=", "$", "this", "->", "getResult", "(", "$", "scroll_id", ")", ";", "return", "$", "this", "->", "getAll", "(", "$", "re...
Get the collection of results @param string $scroll_id @return array|Collection
[ "Get", "the", "collection", "of", "results" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L804-L812
train
basemkhirat/elasticsearch
src/Query.php
Query.first
public function first($scroll_id = NULL) { $this->take(1); $result = $this->getResult($scroll_id); return $this->getFirst($result); }
php
public function first($scroll_id = NULL) { $this->take(1); $result = $this->getResult($scroll_id); return $this->getFirst($result); }
[ "public", "function", "first", "(", "$", "scroll_id", "=", "NULL", ")", "{", "$", "this", "->", "take", "(", "1", ")", ";", "$", "result", "=", "$", "this", "->", "getResult", "(", "$", "scroll_id", ")", ";", "return", "$", "this", "->", "getFirst"...
Get the first object of results @param string $scroll_id @return object
[ "Get", "the", "first", "object", "of", "results" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L819-L827
train
basemkhirat/elasticsearch
src/Query.php
Query.getResult
protected function getResult($scroll_id) { if (is_null($this->cacheMinutes)) { $result = $this->response($scroll_id); } else { $result = app("cache")->driver($this->cacheDriver)->get($this->getCacheKey()); if (is_null($result)) { $result = $this->response($scroll_id); } } return $result; }
php
protected function getResult($scroll_id) { if (is_null($this->cacheMinutes)) { $result = $this->response($scroll_id); } else { $result = app("cache")->driver($this->cacheDriver)->get($this->getCacheKey()); if (is_null($result)) { $result = $this->response($scroll_id); } } return $result; }
[ "protected", "function", "getResult", "(", "$", "scroll_id", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "cacheMinutes", ")", ")", "{", "$", "result", "=", "$", "this", "->", "response", "(", "$", "scroll_id", ")", ";", "}", "else", "{", ...
Get query result @param $scroll_id @return mixed
[ "Get", "query", "result" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L834-L849
train
basemkhirat/elasticsearch
src/Query.php
Query.response
public function response($scroll_id = NULL) { $scroll_id = !is_null($scroll_id) ? $scroll_id : $this->scroll_id; if ($scroll_id) { $result = $this->connection->scroll([ "scroll" => $this->scroll, "scroll_id" => $scroll_id ]); } else { $result = $this->connection->search($this->query()); } if (!is_null($this->cacheMinutes)) { app("cache")->driver($this->cacheDriver)->put($this->getCacheKey(), $result, $this->cacheMinutes); } return $result; }
php
public function response($scroll_id = NULL) { $scroll_id = !is_null($scroll_id) ? $scroll_id : $this->scroll_id; if ($scroll_id) { $result = $this->connection->scroll([ "scroll" => $this->scroll, "scroll_id" => $scroll_id ]); } else { $result = $this->connection->search($this->query()); } if (!is_null($this->cacheMinutes)) { app("cache")->driver($this->cacheDriver)->put($this->getCacheKey(), $result, $this->cacheMinutes); } return $result; }
[ "public", "function", "response", "(", "$", "scroll_id", "=", "NULL", ")", "{", "$", "scroll_id", "=", "!", "is_null", "(", "$", "scroll_id", ")", "?", "$", "scroll_id", ":", "$", "this", "->", "scroll_id", ";", "if", "(", "$", "scroll_id", ")", "{",...
Get non cached results @param null $scroll_id @return mixed
[ "Get", "non", "cached", "results" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L857-L878
train
basemkhirat/elasticsearch
src/Query.php
Query.count
public function count() { $query = $this->query(); // Remove unsupported count query keys unset( $query["size"], $query["from"], $query["body"]["_source"], $query["body"]["sort"] ); return $this->connection->count($query)["count"]; }
php
public function count() { $query = $this->query(); // Remove unsupported count query keys unset( $query["size"], $query["from"], $query["body"]["_source"], $query["body"]["sort"] ); return $this->connection->count($query)["count"]; }
[ "public", "function", "count", "(", ")", "{", "$", "query", "=", "$", "this", "->", "query", "(", ")", ";", "// Remove unsupported count query keys", "unset", "(", "$", "query", "[", "\"size\"", "]", ",", "$", "query", "[", "\"from\"", "]", ",", "$", "...
Get the count of result @return mixed
[ "Get", "the", "count", "of", "result" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L884-L899
train
basemkhirat/elasticsearch
src/Query.php
Query.getFirst
protected function getFirst($result = []) { if (array_key_exists("hits", $result) && count($result["hits"]["hits"])) { $data = $result["hits"]["hits"]; if ($this->model) { $model = new $this->model($data[0]["_source"], true); } else { $model = new Model($data[0]["_source"], true); $model->setConnection($model->getConnection()); $model->setIndex($data[0]["_index"]); $model->setType($data[0]["_type"]); } // match earlier version $model->_index = $data[0]["_index"]; $model->_type = $data[0]["_type"]; $model->_id = $data[0]["_id"]; $model->_score = $data[0]["_score"]; $new = $model; } else { $new = NULL; } return $new; }
php
protected function getFirst($result = []) { if (array_key_exists("hits", $result) && count($result["hits"]["hits"])) { $data = $result["hits"]["hits"]; if ($this->model) { $model = new $this->model($data[0]["_source"], true); } else { $model = new Model($data[0]["_source"], true); $model->setConnection($model->getConnection()); $model->setIndex($data[0]["_index"]); $model->setType($data[0]["_type"]); } // match earlier version $model->_index = $data[0]["_index"]; $model->_type = $data[0]["_type"]; $model->_id = $data[0]["_id"]; $model->_score = $data[0]["_score"]; $new = $model; } else { $new = NULL; } return $new; }
[ "protected", "function", "getFirst", "(", "$", "result", "=", "[", "]", ")", "{", "if", "(", "array_key_exists", "(", "\"hits\"", ",", "$", "result", ")", "&&", "count", "(", "$", "result", "[", "\"hits\"", "]", "[", "\"hits\"", "]", ")", ")", "{", ...
Retrieve only first record @param array $result @return object
[ "Retrieve", "only", "first", "record" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L968-L998
train
basemkhirat/elasticsearch
src/Query.php
Query.paginate
public function paginate($per_page = 10, $page_name = "page", $page = null) { $this->take($per_page); $page = $page ?: Request::get($page_name, 1); $this->skip(($page * $per_page) - $per_page); $objects = $this->get(); return new Pagination($objects, $objects->total, $per_page, $page, ['path' => Request::url(), 'query' => Request::query()]); }
php
public function paginate($per_page = 10, $page_name = "page", $page = null) { $this->take($per_page); $page = $page ?: Request::get($page_name, 1); $this->skip(($page * $per_page) - $per_page); $objects = $this->get(); return new Pagination($objects, $objects->total, $per_page, $page, ['path' => Request::url(), 'query' => Request::query()]); }
[ "public", "function", "paginate", "(", "$", "per_page", "=", "10", ",", "$", "page_name", "=", "\"page\"", ",", "$", "page", "=", "null", ")", "{", "$", "this", "->", "take", "(", "$", "per_page", ")", ";", "$", "page", "=", "$", "page", "?", ":"...
Paginate collection of results @param int $per_page @param $page_name @param null $page @return Pagination
[ "Paginate", "collection", "of", "results" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L1007-L1019
train
basemkhirat/elasticsearch
src/Query.php
Query.bulk
public function bulk($data) { if (is_callback_function($data)) { $bulk = new Bulk($this); $data($bulk); $params = $bulk->body(); } else { $params = []; foreach ($data as $key => $value) { $params["body"][] = [ 'index' => [ '_index' => $this->getIndex(), '_type' => $this->getType(), '_id' => $key ] ]; $params["body"][] = $value; } } return (object)$this->connection->bulk($params); }
php
public function bulk($data) { if (is_callback_function($data)) { $bulk = new Bulk($this); $data($bulk); $params = $bulk->body(); } else { $params = []; foreach ($data as $key => $value) { $params["body"][] = [ 'index' => [ '_index' => $this->getIndex(), '_type' => $this->getType(), '_id' => $key ] ]; $params["body"][] = $value; } } return (object)$this->connection->bulk($params); }
[ "public", "function", "bulk", "(", "$", "data", ")", "{", "if", "(", "is_callback_function", "(", "$", "data", ")", ")", "{", "$", "bulk", "=", "new", "Bulk", "(", "$", "this", ")", ";", "$", "data", "(", "$", "bulk", ")", ";", "$", "params", "...
Insert a bulk of documents @param $data multidimensional array of [id => data] pairs @return object
[ "Insert", "a", "bulk", "of", "documents" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L1059-L1093
train
basemkhirat/elasticsearch
src/Query.php
Query.update
public function update($data, $_id = NULL) { if ($_id) { $this->_id = $_id; } $parameters = [ "id" => $this->_id, "body" => ['doc' => $data], 'client' => ['ignore' => $this->ignores] ]; if ($index = $this->getIndex()) { $parameters["index"] = $index; } if ($type = $this->getType()) { $parameters["type"] = $type; } return (object)$this->connection->update($parameters); }
php
public function update($data, $_id = NULL) { if ($_id) { $this->_id = $_id; } $parameters = [ "id" => $this->_id, "body" => ['doc' => $data], 'client' => ['ignore' => $this->ignores] ]; if ($index = $this->getIndex()) { $parameters["index"] = $index; } if ($type = $this->getType()) { $parameters["type"] = $type; } return (object)$this->connection->update($parameters); }
[ "public", "function", "update", "(", "$", "data", ",", "$", "_id", "=", "NULL", ")", "{", "if", "(", "$", "_id", ")", "{", "$", "this", "->", "_id", "=", "$", "_id", ";", "}", "$", "parameters", "=", "[", "\"id\"", "=>", "$", "this", "->", "_...
Update a document @param $data @param null $_id @return object
[ "Update", "a", "document" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L1101-L1123
train
basemkhirat/elasticsearch
src/Query.php
Query.script
public function script($script, $params = []) { $parameters = [ "id" => $this->_id, "body" => [ "script" => [ "inline" => $script, "params" => $params ] ], 'client' => ['ignore' => $this->ignores] ]; if ($index = $this->getIndex()) { $parameters["index"] = $index; } if ($type = $this->getType()) { $parameters["type"] = $type; } return (object)$this->connection->update($parameters); }
php
public function script($script, $params = []) { $parameters = [ "id" => $this->_id, "body" => [ "script" => [ "inline" => $script, "params" => $params ] ], 'client' => ['ignore' => $this->ignores] ]; if ($index = $this->getIndex()) { $parameters["index"] = $index; } if ($type = $this->getType()) { $parameters["type"] = $type; } return (object)$this->connection->update($parameters); }
[ "public", "function", "script", "(", "$", "script", ",", "$", "params", "=", "[", "]", ")", "{", "$", "parameters", "=", "[", "\"id\"", "=>", "$", "this", "->", "_id", ",", "\"body\"", "=>", "[", "\"script\"", "=>", "[", "\"inline\"", "=>", "$", "s...
Update by script @param $script @param array $params @return object
[ "Update", "by", "script" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L1160-L1183
train
basemkhirat/elasticsearch
src/Query.php
Query.exists
function exists() { $index = new Index($this->index); $index->connection = $this->connection; return $index->exists(); }
php
function exists() { $index = new Index($this->index); $index->connection = $this->connection; return $index->exists(); }
[ "function", "exists", "(", ")", "{", "$", "index", "=", "new", "Index", "(", "$", "this", "->", "index", ")", ";", "$", "index", "->", "connection", "=", "$", "this", "->", "connection", ";", "return", "$", "index", "->", "exists", "(", ")", ";", ...
Check existence of index @return mixed
[ "Check", "existence", "of", "index" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Query.php#L1226-L1234
train
basemkhirat/elasticsearch
src/Classes/Bulk.php
Bulk.action
public function action($actionType, $data = []) { $this->body["body"][] = [ $actionType => [ '_index' => $this->getIndex(), '_type' => $this->getType(), '_id' => $this->_id ] ]; if (!empty($data)) { if($actionType == "update"){ $this->body["body"][] = ["doc" => $data]; }else { $this->body["body"][] = $data; } } $this->operationCount++; $this->reset(); if ($this->autocommitAfter > 0 && $this->operationCount >= $this->autocommitAfter) { return $this->commit(); } return true; }
php
public function action($actionType, $data = []) { $this->body["body"][] = [ $actionType => [ '_index' => $this->getIndex(), '_type' => $this->getType(), '_id' => $this->_id ] ]; if (!empty($data)) { if($actionType == "update"){ $this->body["body"][] = ["doc" => $data]; }else { $this->body["body"][] = $data; } } $this->operationCount++; $this->reset(); if ($this->autocommitAfter > 0 && $this->operationCount >= $this->autocommitAfter) { return $this->commit(); } return true; }
[ "public", "function", "action", "(", "$", "actionType", ",", "$", "data", "=", "[", "]", ")", "{", "$", "this", "->", "body", "[", "\"body\"", "]", "[", "]", "=", "[", "$", "actionType", "=>", "[", "'_index'", "=>", "$", "this", "->", "getIndex", ...
Add pending document abstract action @param string $actionType @param array $data @return mixed
[ "Add", "pending", "document", "abstract", "action" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Classes/Bulk.php#L173-L203
train
basemkhirat/elasticsearch
src/Classes/Bulk.php
Bulk.commit
public function commit() { if (empty($this->body)) { return false; } $result = $this->query->connection->bulk($this->body); $this->operationCount = 0; $this->body = []; return $result; }
php
public function commit() { if (empty($this->body)) { return false; } $result = $this->query->connection->bulk($this->body); $this->operationCount = 0; $this->body = []; return $result; }
[ "public", "function", "commit", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "body", ")", ")", "{", "return", "false", ";", "}", "$", "result", "=", "$", "this", "->", "query", "->", "connection", "->", "bulk", "(", "$", "this", "->...
Commit all pending operations
[ "Commit", "all", "pending", "operations" ]
2ad3f76aadf11dedf1a4075b4cf1373b488f7122
https://github.com/basemkhirat/elasticsearch/blob/2ad3f76aadf11dedf1a4075b4cf1373b488f7122/src/Classes/Bulk.php#L227-L239
train
M6Web/ApiExceptionBundle
Manager/ExceptionManager.php
ExceptionManager.getConfigException
protected function getConfigException($exceptionName) { $exceptionParentName = get_parent_class($exceptionName); if (in_array( 'M6Web\Bundle\ApiExceptionBundle\Exception\Interfaces\ExceptionInterface', class_implements($exceptionParentName) )) { $parentConfig = $this->getConfigException($exceptionParentName); } else { $parentConfig = $this->defaultConfig; } if (isset($this->exceptions[$exceptionName])) { return array_merge($parentConfig, $this->exceptions[$exceptionName]); } return $parentConfig; }
php
protected function getConfigException($exceptionName) { $exceptionParentName = get_parent_class($exceptionName); if (in_array( 'M6Web\Bundle\ApiExceptionBundle\Exception\Interfaces\ExceptionInterface', class_implements($exceptionParentName) )) { $parentConfig = $this->getConfigException($exceptionParentName); } else { $parentConfig = $this->defaultConfig; } if (isset($this->exceptions[$exceptionName])) { return array_merge($parentConfig, $this->exceptions[$exceptionName]); } return $parentConfig; }
[ "protected", "function", "getConfigException", "(", "$", "exceptionName", ")", "{", "$", "exceptionParentName", "=", "get_parent_class", "(", "$", "exceptionName", ")", ";", "if", "(", "in_array", "(", "'M6Web\\Bundle\\ApiExceptionBundle\\Exception\\Interfaces\\ExceptionInt...
Get config to exception @param string $exceptionName @return array
[ "Get", "config", "to", "exception" ]
f615aa3b5fb7b93bdeb8b85e55e745529f86e238
https://github.com/M6Web/ApiExceptionBundle/blob/f615aa3b5fb7b93bdeb8b85e55e745529f86e238/Manager/ExceptionManager.php#L66-L84
train
M6Web/ApiExceptionBundle
DependencyInjection/M6WebApiExceptionExtension.php
M6WebApiExceptionExtension.loadExceptionManager
protected function loadExceptionManager(ContainerBuilder $container, array $config) { $definition = new Definition( 'M6Web\Bundle\ApiExceptionBundle\Manager\ExceptionManager', [ $config['default'], $config['exceptions'], ] ); $definition->setPublic(true); $container->setDefinition($this->getAlias().'.manager.exception', $definition); }
php
protected function loadExceptionManager(ContainerBuilder $container, array $config) { $definition = new Definition( 'M6Web\Bundle\ApiExceptionBundle\Manager\ExceptionManager', [ $config['default'], $config['exceptions'], ] ); $definition->setPublic(true); $container->setDefinition($this->getAlias().'.manager.exception', $definition); }
[ "protected", "function", "loadExceptionManager", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "$", "definition", "=", "new", "Definition", "(", "'M6Web\\Bundle\\ApiExceptionBundle\\Manager\\ExceptionManager'", ",", "[", "$", "config"...
load service exception manager @param ContainerBuilder $container @param array $config
[ "load", "service", "exception", "manager" ]
f615aa3b5fb7b93bdeb8b85e55e745529f86e238
https://github.com/M6Web/ApiExceptionBundle/blob/f615aa3b5fb7b93bdeb8b85e55e745529f86e238/DependencyInjection/M6WebApiExceptionExtension.php#L41-L53
train
M6Web/ApiExceptionBundle
DependencyInjection/M6WebApiExceptionExtension.php
M6WebApiExceptionExtension.loadExceptionListener
protected function loadExceptionListener(ContainerBuilder $container, array $config) { $definition = new Definition( 'M6Web\Bundle\ApiExceptionBundle\EventListener\ExceptionListener', [ new Reference('kernel'), new Reference($this->getAlias().'.manager.exception'), $config['match_all'], $config['default'], $config['stack_trace'], ] ); $definition->setPublic(true); $definition->addTag( 'kernel.event_listener', [ 'event' => 'kernel.exception', 'method' => 'onKernelException', 'priority' => '-100' // as the setResponse stop the exception propagation, this listener has to pass in last position ] ); $container->setDefinition($this->getAlias().'.listener.exception', $definition); }
php
protected function loadExceptionListener(ContainerBuilder $container, array $config) { $definition = new Definition( 'M6Web\Bundle\ApiExceptionBundle\EventListener\ExceptionListener', [ new Reference('kernel'), new Reference($this->getAlias().'.manager.exception'), $config['match_all'], $config['default'], $config['stack_trace'], ] ); $definition->setPublic(true); $definition->addTag( 'kernel.event_listener', [ 'event' => 'kernel.exception', 'method' => 'onKernelException', 'priority' => '-100' // as the setResponse stop the exception propagation, this listener has to pass in last position ] ); $container->setDefinition($this->getAlias().'.listener.exception', $definition); }
[ "protected", "function", "loadExceptionListener", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "$", "definition", "=", "new", "Definition", "(", "'M6Web\\Bundle\\ApiExceptionBundle\\EventListener\\ExceptionListener'", ",", "[", "new", ...
load service exception listener @param ContainerBuilder $container @param array $config
[ "load", "service", "exception", "listener" ]
f615aa3b5fb7b93bdeb8b85e55e745529f86e238
https://github.com/M6Web/ApiExceptionBundle/blob/f615aa3b5fb7b93bdeb8b85e55e745529f86e238/DependencyInjection/M6WebApiExceptionExtension.php#L61-L86
train
M6Web/ApiExceptionBundle
Exception/Exception.php
Exception.getMessageWithVariables
public function getMessageWithVariables() { $message = $this->message; preg_match(self::VARIABLE_REGEX, $message, $variables); foreach ($variables as $variable) { $variableName = substr($variable, 1, -1); if (!isset($this->$variableName)) { throw new \Exception(sprintf( 'Variable "%s" for exception "%s" not found', $variableName, get_class($this) ), 500); } if (!is_string($this->$variableName)) { throw new \Exception(sprintf( 'Variable "%s" for exception "%s" must be a string, %s found', $variableName, get_class($this), gettype($this->$variableName) ), 500); } $message = str_replace($variable, $this->$variableName, $message); } return $message; }
php
public function getMessageWithVariables() { $message = $this->message; preg_match(self::VARIABLE_REGEX, $message, $variables); foreach ($variables as $variable) { $variableName = substr($variable, 1, -1); if (!isset($this->$variableName)) { throw new \Exception(sprintf( 'Variable "%s" for exception "%s" not found', $variableName, get_class($this) ), 500); } if (!is_string($this->$variableName)) { throw new \Exception(sprintf( 'Variable "%s" for exception "%s" must be a string, %s found', $variableName, get_class($this), gettype($this->$variableName) ), 500); } $message = str_replace($variable, $this->$variableName, $message); } return $message; }
[ "public", "function", "getMessageWithVariables", "(", ")", "{", "$", "message", "=", "$", "this", "->", "message", ";", "preg_match", "(", "self", "::", "VARIABLE_REGEX", ",", "$", "message", ",", "$", "variables", ")", ";", "foreach", "(", "$", "variables...
Get message with variables @throws \Exception @return string
[ "Get", "message", "with", "variables" ]
f615aa3b5fb7b93bdeb8b85e55e745529f86e238
https://github.com/M6Web/ApiExceptionBundle/blob/f615aa3b5fb7b93bdeb8b85e55e745529f86e238/Exception/Exception.php#L62-L92
train
M6Web/ApiExceptionBundle
EventListener/ExceptionListener.php
ExceptionListener.onKernelException
public function onKernelException(GetResponseForExceptionEvent $event) { $exception = $event->getException(); if (!($event->getRequest()) || ($this->matchAll === false && !$this->isApiException($exception)) ) { return; } $data = []; if ($this->isApiException($exception)) { $exception = $this->exceptionManager->configure($exception); } $statusCode = $this->getStatusCode($exception); $data['error']['status'] = $statusCode; if ($code = $exception->getCode()) { $data['error']['code'] = $code; } $data['error']['message'] = $this->getMessage($exception); if ($this->isFlattenErrorException($exception)) { $data['error']['errors'] = $exception->getFlattenErrors(); } if ($this->stackTrace) { $data['error']['stack_trace'] = $exception->getTrace(); // Clean stacktrace to avoid circular reference or invalid type array_walk_recursive( $data['error']['stack_trace'], function(&$item) { if (is_object($item)) { $item = get_class($item); } elseif (is_resource($item)) { $item = get_resource_type($item); } } ); } $response = new JsonResponse($data, $statusCode, $this->getHeaders($exception)); $event->setResponse($response); }
php
public function onKernelException(GetResponseForExceptionEvent $event) { $exception = $event->getException(); if (!($event->getRequest()) || ($this->matchAll === false && !$this->isApiException($exception)) ) { return; } $data = []; if ($this->isApiException($exception)) { $exception = $this->exceptionManager->configure($exception); } $statusCode = $this->getStatusCode($exception); $data['error']['status'] = $statusCode; if ($code = $exception->getCode()) { $data['error']['code'] = $code; } $data['error']['message'] = $this->getMessage($exception); if ($this->isFlattenErrorException($exception)) { $data['error']['errors'] = $exception->getFlattenErrors(); } if ($this->stackTrace) { $data['error']['stack_trace'] = $exception->getTrace(); // Clean stacktrace to avoid circular reference or invalid type array_walk_recursive( $data['error']['stack_trace'], function(&$item) { if (is_object($item)) { $item = get_class($item); } elseif (is_resource($item)) { $item = get_resource_type($item); } } ); } $response = new JsonResponse($data, $statusCode, $this->getHeaders($exception)); $event->setResponse($response); }
[ "public", "function", "onKernelException", "(", "GetResponseForExceptionEvent", "$", "event", ")", "{", "$", "exception", "=", "$", "event", "->", "getException", "(", ")", ";", "if", "(", "!", "(", "$", "event", "->", "getRequest", "(", ")", ")", "||", ...
Format response exception @param GetResponseForExceptionEvent $event
[ "Format", "response", "exception" ]
f615aa3b5fb7b93bdeb8b85e55e745529f86e238
https://github.com/M6Web/ApiExceptionBundle/blob/f615aa3b5fb7b93bdeb8b85e55e745529f86e238/EventListener/ExceptionListener.php#L72-L120
train
M6Web/ApiExceptionBundle
EventListener/ExceptionListener.php
ExceptionListener.getStatusCode
private function getStatusCode(\Exception $exception) { $statusCode = $this->default['status']; if ($exception instanceof SymfonyHttpExceptionInterface || $exception instanceof HttpExceptionInterface ) { $statusCode = $exception->getStatusCode(); } return $statusCode; }
php
private function getStatusCode(\Exception $exception) { $statusCode = $this->default['status']; if ($exception instanceof SymfonyHttpExceptionInterface || $exception instanceof HttpExceptionInterface ) { $statusCode = $exception->getStatusCode(); } return $statusCode; }
[ "private", "function", "getStatusCode", "(", "\\", "Exception", "$", "exception", ")", "{", "$", "statusCode", "=", "$", "this", "->", "default", "[", "'status'", "]", ";", "if", "(", "$", "exception", "instanceof", "SymfonyHttpExceptionInterface", "||", "$", ...
Get exception status code @param \Exception $exception @return integer
[ "Get", "exception", "status", "code" ]
f615aa3b5fb7b93bdeb8b85e55e745529f86e238
https://github.com/M6Web/ApiExceptionBundle/blob/f615aa3b5fb7b93bdeb8b85e55e745529f86e238/EventListener/ExceptionListener.php#L129-L140
train
M6Web/ApiExceptionBundle
EventListener/ExceptionListener.php
ExceptionListener.getMessage
private function getMessage(\Exception $exception) { $message = $exception->getMessage(); if ($this->isApiException($exception)) { $message = $exception->getMessageWithVariables(); } return $message; }
php
private function getMessage(\Exception $exception) { $message = $exception->getMessage(); if ($this->isApiException($exception)) { $message = $exception->getMessageWithVariables(); } return $message; }
[ "private", "function", "getMessage", "(", "\\", "Exception", "$", "exception", ")", "{", "$", "message", "=", "$", "exception", "->", "getMessage", "(", ")", ";", "if", "(", "$", "this", "->", "isApiException", "(", "$", "exception", ")", ")", "{", "$"...
Get exception message @param \Exception $exception @return integer
[ "Get", "exception", "message" ]
f615aa3b5fb7b93bdeb8b85e55e745529f86e238
https://github.com/M6Web/ApiExceptionBundle/blob/f615aa3b5fb7b93bdeb8b85e55e745529f86e238/EventListener/ExceptionListener.php#L149-L158
train
M6Web/ApiExceptionBundle
EventListener/ExceptionListener.php
ExceptionListener.getHeaders
private function getHeaders(\Exception $exception) { $headers = $this->default['headers']; if ($exception instanceof SymfonyHttpExceptionInterface || $exception instanceof HttpExceptionInterface ) { $headers = $exception->getHeaders(); } return $headers; }
php
private function getHeaders(\Exception $exception) { $headers = $this->default['headers']; if ($exception instanceof SymfonyHttpExceptionInterface || $exception instanceof HttpExceptionInterface ) { $headers = $exception->getHeaders(); } return $headers; }
[ "private", "function", "getHeaders", "(", "\\", "Exception", "$", "exception", ")", "{", "$", "headers", "=", "$", "this", "->", "default", "[", "'headers'", "]", ";", "if", "(", "$", "exception", "instanceof", "SymfonyHttpExceptionInterface", "||", "$", "ex...
Get exception headers @param \Exception $exception @return array
[ "Get", "exception", "headers" ]
f615aa3b5fb7b93bdeb8b85e55e745529f86e238
https://github.com/M6Web/ApiExceptionBundle/blob/f615aa3b5fb7b93bdeb8b85e55e745529f86e238/EventListener/ExceptionListener.php#L167-L178
train
M6Web/ApiExceptionBundle
Exception/ValidationFormException.php
ValidationFormException.getFlattenErrors
public function getFlattenErrors(FormInterface $form = null, $subForm = false) { $form = $form ?: $this->form; $flatten = []; foreach ($form->getErrors() as $error) { if ($subForm) { $flatten[] = $error->getMessage(); } else { $path = $error->getCause()->getPropertyPath(); if (!array_key_exists($path, $flatten)) { $flatten[$path] = [$error->getMessage()]; continue; } $flatten[$path][] = $error->getMessage(); } } $subForm = true; foreach ($form->all() as $key => $child) { $childErrors = $this->getFlattenErrors($child, $subForm); if (!empty($childErrors)) { $flatten[$key] = $childErrors; } } return $flatten; }
php
public function getFlattenErrors(FormInterface $form = null, $subForm = false) { $form = $form ?: $this->form; $flatten = []; foreach ($form->getErrors() as $error) { if ($subForm) { $flatten[] = $error->getMessage(); } else { $path = $error->getCause()->getPropertyPath(); if (!array_key_exists($path, $flatten)) { $flatten[$path] = [$error->getMessage()]; continue; } $flatten[$path][] = $error->getMessage(); } } $subForm = true; foreach ($form->all() as $key => $child) { $childErrors = $this->getFlattenErrors($child, $subForm); if (!empty($childErrors)) { $flatten[$key] = $childErrors; } } return $flatten; }
[ "public", "function", "getFlattenErrors", "(", "FormInterface", "$", "form", "=", "null", ",", "$", "subForm", "=", "false", ")", "{", "$", "form", "=", "$", "form", "?", ":", "$", "this", "->", "form", ";", "$", "flatten", "=", "[", "]", ";", "for...
Flatten form errors @param FormInterface $form @param boolean $subForm @return array
[ "Flatten", "form", "errors" ]
f615aa3b5fb7b93bdeb8b85e55e745529f86e238
https://github.com/M6Web/ApiExceptionBundle/blob/f615aa3b5fb7b93bdeb8b85e55e745529f86e238/Exception/ValidationFormException.php#L56-L86
train
zbateson/mail-mime-parser
src/Header/Consumer/Received/GenericReceivedConsumer.php
GenericReceivedConsumer.processParts
protected function processParts(array $parts) { $strValue = ''; $ret = []; $filtered = $this->filterIgnoredSpaces($parts); foreach ($filtered as $part) { if ($part instanceof CommentPart) { $ret[] = $part; continue; // getValue() is empty anyway, but for clarity... } $strValue .= $part->getValue(); } array_unshift($ret, $this->partFactory->newReceivedPart($this->getPartName(), $strValue)); return $ret; }
php
protected function processParts(array $parts) { $strValue = ''; $ret = []; $filtered = $this->filterIgnoredSpaces($parts); foreach ($filtered as $part) { if ($part instanceof CommentPart) { $ret[] = $part; continue; // getValue() is empty anyway, but for clarity... } $strValue .= $part->getValue(); } array_unshift($ret, $this->partFactory->newReceivedPart($this->getPartName(), $strValue)); return $ret; }
[ "protected", "function", "processParts", "(", "array", "$", "parts", ")", "{", "$", "strValue", "=", "''", ";", "$", "ret", "=", "[", "]", ";", "$", "filtered", "=", "$", "this", "->", "filterIgnoredSpaces", "(", "$", "parts", ")", ";", "foreach", "(...
Overridden to combine all part values into a single string and return it as the first element, followed by any comment elements as subsequent elements. @param \ZBateson\MailMimeParser\Header\Part\HeaderPart[] $parts @return \ZBateson\MailMimeParser\Header\Part\HeaderPart[]| \ZBateson\MailMimeParser\Header\Part\CommentPart[]| array
[ "Overridden", "to", "combine", "all", "part", "values", "into", "a", "single", "string", "and", "return", "it", "as", "the", "first", "element", "followed", "by", "any", "comment", "elements", "as", "subsequent", "elements", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Header/Consumer/Received/GenericReceivedConsumer.php#L140-L154
train
zbateson/mail-mime-parser
src/Header/Part/AddressGroupPart.php
AddressGroupPart.getAddress
public function getAddress($index) { if (!isset($this->addresses[$index])) { return null; } return $this->addresses[$index]; }
php
public function getAddress($index) { if (!isset($this->addresses[$index])) { return null; } return $this->addresses[$index]; }
[ "public", "function", "getAddress", "(", "$", "index", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "addresses", "[", "$", "index", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "addresses", "[", "$", ...
Returns the AddressPart at the passed index or null. @param int $index @return Address
[ "Returns", "the", "AddressPart", "at", "the", "passed", "index", "or", "null", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Header/Part/AddressGroupPart.php#L58-L64
train
zbateson/mail-mime-parser
src/Header/Consumer/CommentConsumer.php
CommentConsumer.processParts
protected function processParts(array $parts) { $comment = ''; foreach ($parts as $part) { // order is important here - CommentPart extends LiteralPart if ($part instanceof CommentPart) { $comment .= '(' . $part->getComment() . ')'; } elseif ($part instanceof LiteralPart) { $comment .= '"' . $part->getValue() . '"'; } else { $comment .= $part->getValue(); } } return [$this->partFactory->newCommentPart($comment)]; }
php
protected function processParts(array $parts) { $comment = ''; foreach ($parts as $part) { // order is important here - CommentPart extends LiteralPart if ($part instanceof CommentPart) { $comment .= '(' . $part->getComment() . ')'; } elseif ($part instanceof LiteralPart) { $comment .= '"' . $part->getValue() . '"'; } else { $comment .= $part->getValue(); } } return [$this->partFactory->newCommentPart($comment)]; }
[ "protected", "function", "processParts", "(", "array", "$", "parts", ")", "{", "$", "comment", "=", "''", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "// order is important here - CommentPart extends LiteralPart", "if", "(", "$", "part", "i...
Post processing involves creating a single Part\CommentPart out of generated parts from tokens. The Part\CommentPart is returned in an array. @param \ZBateson\MailMimeParser\Header\Part\HeaderPart[] $parts @return \ZBateson\MailMimeParser\Header\Part\HeaderPart[]|array
[ "Post", "processing", "involves", "creating", "a", "single", "Part", "\\", "CommentPart", "out", "of", "generated", "parts", "from", "tokens", ".", "The", "Part", "\\", "CommentPart", "is", "returned", "in", "an", "array", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Header/Consumer/CommentConsumer.php#L106-L120
train
zbateson/mail-mime-parser
src/Header/Consumer/Received/DomainConsumer.php
DomainConsumer.matchHostPart
private function matchHostPart($value, &$hostname, &$address) { $matches = []; $pattern = '~^(?P<name>[a-z0-9\-]+\.[a-z0-9\-\.]+)?\s*(\[(IPv[64])?(?P<addr>[a-f\d\.\:]+)\])?$~i'; if (preg_match($pattern, $value, $matches)) { if (!empty($matches['name'])) { $hostname = $matches['name']; } if (!empty($matches['addr'])) { $address = $matches['addr']; } return true; } return false; }
php
private function matchHostPart($value, &$hostname, &$address) { $matches = []; $pattern = '~^(?P<name>[a-z0-9\-]+\.[a-z0-9\-\.]+)?\s*(\[(IPv[64])?(?P<addr>[a-f\d\.\:]+)\])?$~i'; if (preg_match($pattern, $value, $matches)) { if (!empty($matches['name'])) { $hostname = $matches['name']; } if (!empty($matches['addr'])) { $address = $matches['addr']; } return true; } return false; }
[ "private", "function", "matchHostPart", "(", "$", "value", ",", "&", "$", "hostname", ",", "&", "$", "address", ")", "{", "$", "matches", "=", "[", "]", ";", "$", "pattern", "=", "'~^(?P<name>[a-z0-9\\-]+\\.[a-z0-9\\-\\.]+)?\\s*(\\[(IPv[64])?(?P<addr>[a-f\\d\\.\\:]+...
Attempts to match a parenthesized expression to find a hostname and an address. Returns true if the expression matched, and either hostname or address were found. @param string $value @param string $hostname @param string $address @return boolean
[ "Attempts", "to", "match", "a", "parenthesized", "expression", "to", "find", "a", "hostname", "and", "an", "address", ".", "Returns", "true", "if", "the", "expression", "matched", "and", "either", "hostname", "or", "address", "were", "found", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Header/Consumer/Received/DomainConsumer.php#L70-L83
train
zbateson/mail-mime-parser
src/Header/Consumer/Received/DomainConsumer.php
DomainConsumer.processParts
protected function processParts(array $parts) { $ehloName = null; $hostname = null; $address = null; $commentPart = null; $filtered = $this->filterIgnoredSpaces($parts); foreach ($filtered as $part) { if ($part instanceof CommentPart) { $commentPart = $part; continue; } $ehloName .= $part->getValue(); } $strValue = $ehloName; if ($commentPart !== null && $this->matchHostPart($commentPart->getComment(), $hostname, $address)) { $strValue .= ' (' . $commentPart->getComment() . ')'; $commentPart = null; } $domainPart = $this->partFactory->newReceivedDomainPart( $this->getPartName(), $strValue, $ehloName, $hostname, $address ); return array_filter([ $domainPart, $commentPart ]); }
php
protected function processParts(array $parts) { $ehloName = null; $hostname = null; $address = null; $commentPart = null; $filtered = $this->filterIgnoredSpaces($parts); foreach ($filtered as $part) { if ($part instanceof CommentPart) { $commentPart = $part; continue; } $ehloName .= $part->getValue(); } $strValue = $ehloName; if ($commentPart !== null && $this->matchHostPart($commentPart->getComment(), $hostname, $address)) { $strValue .= ' (' . $commentPart->getComment() . ')'; $commentPart = null; } $domainPart = $this->partFactory->newReceivedDomainPart( $this->getPartName(), $strValue, $ehloName, $hostname, $address ); return array_filter([ $domainPart, $commentPart ]); }
[ "protected", "function", "processParts", "(", "array", "$", "parts", ")", "{", "$", "ehloName", "=", "null", ";", "$", "hostname", "=", "null", ";", "$", "address", "=", "null", ";", "$", "commentPart", "=", "null", ";", "$", "filtered", "=", "$", "t...
Creates a single ReceivedDomainPart out of matched parts. If an unmatched parenthesized expression was found, it's returned as a CommentPart. @param \ZBateson\MailMimeParser\Header\Part\HeaderPart[] $parts @return \ZBateson\MailMimeParser\Header\Part\ReceivedDomainPart[]| \ZBateson\MailMimeParser\Header\Part\CommentPart[]array
[ "Creates", "a", "single", "ReceivedDomainPart", "out", "of", "matched", "parts", ".", "If", "an", "unmatched", "parenthesized", "expression", "was", "found", "it", "s", "returned", "as", "a", "CommentPart", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Header/Consumer/Received/DomainConsumer.php#L94-L124
train
zbateson/mail-mime-parser
src/Header/Part/SplitParameterToken.php
SplitParameterToken.addPart
public function addPart($value, $isEncoded, $index) { if (empty($index)) { $index = 0; } if ($isEncoded) { $this->extractMetaInformationAndValue($value, $index); } else { $this->literalParts[$index] = $this->convertEncoding($value); } }
php
public function addPart($value, $isEncoded, $index) { if (empty($index)) { $index = 0; } if ($isEncoded) { $this->extractMetaInformationAndValue($value, $index); } else { $this->literalParts[$index] = $this->convertEncoding($value); } }
[ "public", "function", "addPart", "(", "$", "value", ",", "$", "isEncoded", ",", "$", "index", ")", "{", "if", "(", "empty", "(", "$", "index", ")", ")", "{", "$", "index", "=", "0", ";", "}", "if", "(", "$", "isEncoded", ")", "{", "$", "this", ...
Adds the passed part to the running array of values. If $isEncoded is true, language and charset info is extracted from the value, and the value is decoded before returning in getValue. The value of the parameter is sorted based on the passed $index arguments when adding before concatenating when re-constructing the value. @param string $value @param boolean $isEncoded @param int $index
[ "Adds", "the", "passed", "part", "to", "the", "running", "array", "of", "values", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Header/Part/SplitParameterToken.php#L98-L108
train
zbateson/mail-mime-parser
src/Header/Part/SplitParameterToken.php
SplitParameterToken.getValue
public function getValue() { $parts = $this->literalParts; reset($this->encodedParts); ksort($this->encodedParts); while (current($this->encodedParts) !== false) { $parts[key($this->encodedParts)] = $this->getNextEncodedValue(); } ksort($parts); return array_reduce( $parts, function ($carry, $item) { return $carry . $item; }, '' ); }
php
public function getValue() { $parts = $this->literalParts; reset($this->encodedParts); ksort($this->encodedParts); while (current($this->encodedParts) !== false) { $parts[key($this->encodedParts)] = $this->getNextEncodedValue(); } ksort($parts); return array_reduce( $parts, function ($carry, $item) { return $carry . $item; }, '' ); }
[ "public", "function", "getValue", "(", ")", "{", "$", "parts", "=", "$", "this", "->", "literalParts", ";", "reset", "(", "$", "this", "->", "encodedParts", ")", ";", "ksort", "(", "$", "this", "->", "encodedParts", ")", ";", "while", "(", "current", ...
Reconstructs the value of the split parameter into a single UTF-8 string and returns it. @return string
[ "Reconstructs", "the", "value", "of", "the", "split", "parameter", "into", "a", "single", "UTF", "-", "8", "string", "and", "returns", "it", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Header/Part/SplitParameterToken.php#L148-L166
train
zbateson/mail-mime-parser
src/Message/PartFilter.php
PartFilter.setHeaders
public function setHeaders(array $headers) { array_walk($headers, function ($v, $k) { $this->validateArgument( 'headers', $k, [ static::FILTER_EXCLUDE, static::FILTER_INCLUDE ] ); if (!is_array($v)) { throw new InvalidArgumentException( '$value must be an array with keys set to FILTER_EXCLUDE, ' . 'FILTER_INCLUDE and values set to an array of header ' . 'name => values' ); } }); $this->headers = $headers; }
php
public function setHeaders(array $headers) { array_walk($headers, function ($v, $k) { $this->validateArgument( 'headers', $k, [ static::FILTER_EXCLUDE, static::FILTER_INCLUDE ] ); if (!is_array($v)) { throw new InvalidArgumentException( '$value must be an array with keys set to FILTER_EXCLUDE, ' . 'FILTER_INCLUDE and values set to an array of header ' . 'name => values' ); } }); $this->headers = $headers; }
[ "public", "function", "setHeaders", "(", "array", "$", "headers", ")", "{", "array_walk", "(", "$", "headers", ",", "function", "(", "$", "v", ",", "$", "k", ")", "{", "$", "this", "->", "validateArgument", "(", "'headers'", ",", "$", "k", ",", "[", ...
Sets the PartFilter's headers filter to the passed array after validating it. @param array $headers @throws InvalidArgumentException
[ "Sets", "the", "PartFilter", "s", "headers", "filter", "to", "the", "passed", "array", "after", "validating", "it", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Message/PartFilter.php#L207-L224
train
zbateson/mail-mime-parser
src/Message/PartFilter.php
PartFilter.failsHasContentFilter
private function failsHasContentFilter(MessagePart $part) { return ($this->hascontent === static::FILTER_EXCLUDE && $part->hasContent()) || ($this->hascontent === static::FILTER_INCLUDE && !$part->hasContent()); }
php
private function failsHasContentFilter(MessagePart $part) { return ($this->hascontent === static::FILTER_EXCLUDE && $part->hasContent()) || ($this->hascontent === static::FILTER_INCLUDE && !$part->hasContent()); }
[ "private", "function", "failsHasContentFilter", "(", "MessagePart", "$", "part", ")", "{", "return", "(", "$", "this", "->", "hascontent", "===", "static", "::", "FILTER_EXCLUDE", "&&", "$", "part", "->", "hasContent", "(", ")", ")", "||", "(", "$", "this"...
Returns true if the passed MessagePart fails the filter's hascontent filter settings. @param MessagePart $part @return bool
[ "Returns", "true", "if", "the", "passed", "MessagePart", "fails", "the", "filter", "s", "hascontent", "filter", "settings", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Message/PartFilter.php#L285-L289
train
zbateson/mail-mime-parser
src/Message/PartFilter.php
PartFilter.failsMultiPartFilter
private function failsMultiPartFilter(MessagePart $part) { if (!($part instanceof MimePart)) { return $this->multipart !== static::FILTER_EXCLUDE; } return ($this->multipart === static::FILTER_EXCLUDE && $part->isMultiPart()) || ($this->multipart === static::FILTER_INCLUDE && !$part->isMultiPart()); }
php
private function failsMultiPartFilter(MessagePart $part) { if (!($part instanceof MimePart)) { return $this->multipart !== static::FILTER_EXCLUDE; } return ($this->multipart === static::FILTER_EXCLUDE && $part->isMultiPart()) || ($this->multipart === static::FILTER_INCLUDE && !$part->isMultiPart()); }
[ "private", "function", "failsMultiPartFilter", "(", "MessagePart", "$", "part", ")", "{", "if", "(", "!", "(", "$", "part", "instanceof", "MimePart", ")", ")", "{", "return", "$", "this", "->", "multipart", "!==", "static", "::", "FILTER_EXCLUDE", ";", "}"...
Returns true if the passed MessagePart fails the filter's multipart filter settings. @param MessagePart $part @return bool
[ "Returns", "true", "if", "the", "passed", "MessagePart", "fails", "the", "filter", "s", "multipart", "filter", "settings", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Message/PartFilter.php#L298-L305
train
zbateson/mail-mime-parser
src/Message/PartFilter.php
PartFilter.failsTextPartFilter
private function failsTextPartFilter(MessagePart $part) { return ($this->textpart === static::FILTER_EXCLUDE && $part->isTextPart()) || ($this->textpart === static::FILTER_INCLUDE && !$part->isTextPart()); }
php
private function failsTextPartFilter(MessagePart $part) { return ($this->textpart === static::FILTER_EXCLUDE && $part->isTextPart()) || ($this->textpart === static::FILTER_INCLUDE && !$part->isTextPart()); }
[ "private", "function", "failsTextPartFilter", "(", "MessagePart", "$", "part", ")", "{", "return", "(", "$", "this", "->", "textpart", "===", "static", "::", "FILTER_EXCLUDE", "&&", "$", "part", "->", "isTextPart", "(", ")", ")", "||", "(", "$", "this", ...
Returns true if the passed MessagePart fails the filter's textpart filter settings. @param MessagePart $part @return bool
[ "Returns", "true", "if", "the", "passed", "MessagePart", "fails", "the", "filter", "s", "textpart", "filter", "settings", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Message/PartFilter.php#L314-L318
train
zbateson/mail-mime-parser
src/Message/PartFilter.php
PartFilter.failsSignedPartFilter
private function failsSignedPartFilter(MessagePart $part) { if ($this->signedpart === static::FILTER_OFF) { return false; } elseif (!$part->isMime() || $part->getParent() === null) { return ($this->signedpart === static::FILTER_INCLUDE); } $partMimeType = $part->getContentType(); $parentMimeType = $part->getParent()->getContentType(); $parentProtocol = $part->getParent()->getHeaderParameter('Content-Type', 'protocol'); if (strcasecmp($parentMimeType, 'multipart/signed') === 0 && strcasecmp($partMimeType, $parentProtocol) === 0) { return ($this->signedpart === static::FILTER_EXCLUDE); } return ($this->signedpart === static::FILTER_INCLUDE); }
php
private function failsSignedPartFilter(MessagePart $part) { if ($this->signedpart === static::FILTER_OFF) { return false; } elseif (!$part->isMime() || $part->getParent() === null) { return ($this->signedpart === static::FILTER_INCLUDE); } $partMimeType = $part->getContentType(); $parentMimeType = $part->getParent()->getContentType(); $parentProtocol = $part->getParent()->getHeaderParameter('Content-Type', 'protocol'); if (strcasecmp($parentMimeType, 'multipart/signed') === 0 && strcasecmp($partMimeType, $parentProtocol) === 0) { return ($this->signedpart === static::FILTER_EXCLUDE); } return ($this->signedpart === static::FILTER_INCLUDE); }
[ "private", "function", "failsSignedPartFilter", "(", "MessagePart", "$", "part", ")", "{", "if", "(", "$", "this", "->", "signedpart", "===", "static", "::", "FILTER_OFF", ")", "{", "return", "false", ";", "}", "elseif", "(", "!", "$", "part", "->", "isM...
Returns true if the passed MessagePart fails the filter's signedpart filter settings. @param MessagePart $part @return boolean
[ "Returns", "true", "if", "the", "passed", "MessagePart", "fails", "the", "filter", "s", "signedpart", "filter", "settings", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Message/PartFilter.php#L327-L341
train
zbateson/mail-mime-parser
src/Message/PartFilter.php
PartFilter.failsHeaderPartFilter
private function failsHeaderPartFilter(MessagePart $part) { foreach ($this->headers as $type => $values) { foreach ($values as $name => $header) { if ($this->failsHeaderFor($part, $type, $name, $header)) { return true; } } } return false; }
php
private function failsHeaderPartFilter(MessagePart $part) { foreach ($this->headers as $type => $values) { foreach ($values as $name => $header) { if ($this->failsHeaderFor($part, $type, $name, $header)) { return true; } } } return false; }
[ "private", "function", "failsHeaderPartFilter", "(", "MessagePart", "$", "part", ")", "{", "foreach", "(", "$", "this", "->", "headers", "as", "$", "type", "=>", "$", "values", ")", "{", "foreach", "(", "$", "values", "as", "$", "name", "=>", "$", "hea...
Returns true if the passed MessagePart fails the filter's header filter settings. @param MessagePart $part @return boolean
[ "Returns", "true", "if", "the", "passed", "MessagePart", "fails", "the", "filter", "s", "header", "filter", "settings", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Message/PartFilter.php#L384-L394
train
zbateson/mail-mime-parser
src/Message/PartFilter.php
PartFilter.filter
public function filter(MessagePart $part) { return !($this->failsMultiPartFilter($part) || $this->failsTextPartFilter($part) || $this->failsSignedPartFilter($part) || $this->failsHeaderPartFilter($part)); }
php
public function filter(MessagePart $part) { return !($this->failsMultiPartFilter($part) || $this->failsTextPartFilter($part) || $this->failsSignedPartFilter($part) || $this->failsHeaderPartFilter($part)); }
[ "public", "function", "filter", "(", "MessagePart", "$", "part", ")", "{", "return", "!", "(", "$", "this", "->", "failsMultiPartFilter", "(", "$", "part", ")", "||", "$", "this", "->", "failsTextPartFilter", "(", "$", "part", ")", "||", "$", "this", "...
Determines if the passed MessagePart should be filtered out or not. If the MessagePart passes all filter tests, true is returned. Otherwise false is returned. @param MessagePart $part @return boolean
[ "Determines", "if", "the", "passed", "MessagePart", "should", "be", "filtered", "out", "or", "not", ".", "If", "the", "MessagePart", "passes", "all", "filter", "tests", "true", "is", "returned", ".", "Otherwise", "false", "is", "returned", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Message/PartFilter.php#L404-L410
train
zbateson/mail-mime-parser
src/Message/Helper/MultipartHelper.php
MultipartHelper.getUniqueBoundary
public function getUniqueBoundary($mimeType) { $type = ltrim(strtoupper(preg_replace('/^(multipart\/(.{3}).*|.*)$/i', '$2-', $mimeType)), '-'); return uniqid('----=MMP-' . $type . '.', true); }
php
public function getUniqueBoundary($mimeType) { $type = ltrim(strtoupper(preg_replace('/^(multipart\/(.{3}).*|.*)$/i', '$2-', $mimeType)), '-'); return uniqid('----=MMP-' . $type . '.', true); }
[ "public", "function", "getUniqueBoundary", "(", "$", "mimeType", ")", "{", "$", "type", "=", "ltrim", "(", "strtoupper", "(", "preg_replace", "(", "'/^(multipart\\/(.{3}).*|.*)$/i'", ",", "'$2-'", ",", "$", "mimeType", ")", ")", ",", "'-'", ")", ";", "return...
Creates and returns a unique boundary. @param string $mimeType first 3 characters of a multipart type are used, e.g. REL for relative or ALT for alternative @return string
[ "Creates", "and", "returns", "a", "unique", "boundary", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Message/Helper/MultipartHelper.php#L57-L61
train
zbateson/mail-mime-parser
src/Message/Helper/MultipartHelper.php
MultipartHelper.findOtherContentPartFor
public function findOtherContentPartFor(Message $message, $mimeType) { $altPart = $message->getPart( 0, PartFilter::fromInlineContentType(($mimeType === 'text/plain') ? 'text/html' : 'text/plain') ); if ($altPart !== null && $altPart->getParent() !== null && $altPart->getParent()->isMultiPart()) { $altPartParent = $altPart->getParent(); if ($altPartParent->getChildCount(PartFilter::fromDisposition('inline', PartFilter::FILTER_EXCLUDE)) !== 1) { $altPart = $this->createMultipartRelatedPartForInlineChildrenOf($altPartParent); } } return $altPart; }
php
public function findOtherContentPartFor(Message $message, $mimeType) { $altPart = $message->getPart( 0, PartFilter::fromInlineContentType(($mimeType === 'text/plain') ? 'text/html' : 'text/plain') ); if ($altPart !== null && $altPart->getParent() !== null && $altPart->getParent()->isMultiPart()) { $altPartParent = $altPart->getParent(); if ($altPartParent->getChildCount(PartFilter::fromDisposition('inline', PartFilter::FILTER_EXCLUDE)) !== 1) { $altPart = $this->createMultipartRelatedPartForInlineChildrenOf($altPartParent); } } return $altPart; }
[ "public", "function", "findOtherContentPartFor", "(", "Message", "$", "message", ",", "$", "mimeType", ")", "{", "$", "altPart", "=", "$", "message", "->", "getPart", "(", "0", ",", "PartFilter", "::", "fromInlineContentType", "(", "(", "$", "mimeType", "===...
Finds an alternative inline part in the message and returns it if one exists. If the passed $mimeType is text/plain, searches for a text/html part. Otherwise searches for a text/plain part to return. @param Message $message @param string $mimeType @return \ZBateson\MailMimeParser\Message\Part\MimeType or null if not found
[ "Finds", "an", "alternative", "inline", "part", "in", "the", "message", "and", "returns", "it", "if", "one", "exists", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Message/Helper/MultipartHelper.php#L285-L298
train
zbateson/mail-mime-parser
src/Message/Helper/MultipartHelper.php
MultipartHelper.createAndAddPartForAttachment
public function createAndAddPartForAttachment(Message $message, $resource, $mimeType, $disposition, $filename = null) { if ($filename === null) { $filename = 'file' . uniqid(); } $safe = iconv('UTF-8', 'US-ASCII//translit//ignore', $filename); if ($message->isMime()) { $builder = $this->partBuilderFactory->newPartBuilder($this->mimePartFactory); $builder->addHeader('Content-Transfer-Encoding', 'base64'); if (strcasecmp($message->getContentType(), 'multipart/mixed') !== 0) { $this->setMessageAsMixed($message); } $builder->addHeader('Content-Type', "$mimeType;\r\n\tname=\"$safe\""); $builder->addHeader('Content-Disposition', "$disposition;\r\n\tfilename=\"$safe\""); } else { $builder = $this->partBuilderFactory->newPartBuilder( $this->uuEncodedPartFactory ); $builder->setProperty('filename', $safe); } $part = $builder->createMessagePart(); $part->setContent($resource); $message->addChild($part); }
php
public function createAndAddPartForAttachment(Message $message, $resource, $mimeType, $disposition, $filename = null) { if ($filename === null) { $filename = 'file' . uniqid(); } $safe = iconv('UTF-8', 'US-ASCII//translit//ignore', $filename); if ($message->isMime()) { $builder = $this->partBuilderFactory->newPartBuilder($this->mimePartFactory); $builder->addHeader('Content-Transfer-Encoding', 'base64'); if (strcasecmp($message->getContentType(), 'multipart/mixed') !== 0) { $this->setMessageAsMixed($message); } $builder->addHeader('Content-Type', "$mimeType;\r\n\tname=\"$safe\""); $builder->addHeader('Content-Disposition', "$disposition;\r\n\tfilename=\"$safe\""); } else { $builder = $this->partBuilderFactory->newPartBuilder( $this->uuEncodedPartFactory ); $builder->setProperty('filename', $safe); } $part = $builder->createMessagePart(); $part->setContent($resource); $message->addChild($part); }
[ "public", "function", "createAndAddPartForAttachment", "(", "Message", "$", "message", ",", "$", "resource", ",", "$", "mimeType", ",", "$", "disposition", ",", "$", "filename", "=", "null", ")", "{", "if", "(", "$", "filename", "===", "null", ")", "{", ...
Creates and adds a MimePart for the passed content and options as an attachment. @param Message $message @param string|resource|Psr\Http\Message\StreamInterface\StreamInterface $resource @param string $mimeType @param string $disposition @param string $filename @return \ZBateson\MailMimeParser\Message\Part\MimePart
[ "Creates", "and", "adds", "a", "MimePart", "for", "the", "passed", "content", "and", "options", "as", "an", "attachment", "." ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Message/Helper/MultipartHelper.php#L344-L368
train
zbateson/mail-mime-parser
src/Message/Helper/MultipartHelper.php
MultipartHelper.removeAllContentPartsByMimeType
public function removeAllContentPartsByMimeType(Message $message, $mimeType, $keepOtherContent = false) { $alt = $message->getPart(0, PartFilter::fromInlineContentType('multipart/alternative')); if ($alt !== null) { return $this->removeAllContentPartsFromAlternative($message, $mimeType, $alt, $keepOtherContent); } $message->removeAllParts(PartFilter::fromInlineContentType($mimeType)); return true; }
php
public function removeAllContentPartsByMimeType(Message $message, $mimeType, $keepOtherContent = false) { $alt = $message->getPart(0, PartFilter::fromInlineContentType('multipart/alternative')); if ($alt !== null) { return $this->removeAllContentPartsFromAlternative($message, $mimeType, $alt, $keepOtherContent); } $message->removeAllParts(PartFilter::fromInlineContentType($mimeType)); return true; }
[ "public", "function", "removeAllContentPartsByMimeType", "(", "Message", "$", "message", ",", "$", "mimeType", ",", "$", "keepOtherContent", "=", "false", ")", "{", "$", "alt", "=", "$", "message", "->", "getPart", "(", "0", ",", "PartFilter", "::", "fromInl...
Removes the content part of the message with the passed mime type. If there is a remaining content part and it is an alternative part of the main message, the content part is moved to the message part. If the content part is part of an alternative part beneath the message, the alternative part is replaced by the remaining content part, optionally keeping other parts if $keepOtherContent is set to true. @param Message $message @param string $mimeType @param bool $keepOtherContent @return boolean true on success
[ "Removes", "the", "content", "part", "of", "the", "message", "with", "the", "passed", "mime", "type", ".", "If", "there", "is", "a", "remaining", "content", "part", "and", "it", "is", "an", "alternative", "part", "of", "the", "main", "message", "the", "c...
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Message/Helper/MultipartHelper.php#L384-L392
train
zbateson/mail-mime-parser
src/Message/Helper/MultipartHelper.php
MultipartHelper.removePartByMimeType
public function removePartByMimeType(Message $message, $mimeType, $index = 0) { $parts = $message->getAllParts(PartFilter::fromInlineContentType($mimeType)); $alt = $message->getPart(0, PartFilter::fromInlineContentType('multipart/alternative')); if ($parts === null || !isset($parts[$index])) { return false; } elseif (count($parts) === 1) { return $this->removeAllContentPartsByMimeType($message, $mimeType, true); } $part = $parts[$index]; $message->removePart($part); if ($alt !== null && $alt->getChildCount() === 1) { $this->genericHelper->replacePart($message, $alt, $alt->getChild(0)); } return true; }
php
public function removePartByMimeType(Message $message, $mimeType, $index = 0) { $parts = $message->getAllParts(PartFilter::fromInlineContentType($mimeType)); $alt = $message->getPart(0, PartFilter::fromInlineContentType('multipart/alternative')); if ($parts === null || !isset($parts[$index])) { return false; } elseif (count($parts) === 1) { return $this->removeAllContentPartsByMimeType($message, $mimeType, true); } $part = $parts[$index]; $message->removePart($part); if ($alt !== null && $alt->getChildCount() === 1) { $this->genericHelper->replacePart($message, $alt, $alt->getChild(0)); } return true; }
[ "public", "function", "removePartByMimeType", "(", "Message", "$", "message", ",", "$", "mimeType", ",", "$", "index", "=", "0", ")", "{", "$", "parts", "=", "$", "message", "->", "getAllParts", "(", "PartFilter", "::", "fromInlineContentType", "(", "$", "...
Removes the 'inline' part with the passed contentType, at the given index defaulting to the first @param Message $message @param string $mimeType @param int $index @return boolean true on success
[ "Removes", "the", "inline", "part", "with", "the", "passed", "contentType", "at", "the", "given", "index", "defaulting", "to", "the", "first" ]
63bedd7d71fb3abff2381174a14637c5a4ddaa36
https://github.com/zbateson/mail-mime-parser/blob/63bedd7d71fb3abff2381174a14637c5a4ddaa36/src/Message/Helper/MultipartHelper.php#L403-L418
train
ZimTis/array-validation
src/ValidationBuilder.php
ValidationBuilder.buildValidation
public static function buildValidation(array $schema, $name = null) { $validation = new NestedValidation($name); foreach ($schema as $key => $value) { if (!is_array($value)) { trigger_error('parsing error', E_USER_ERROR); } if (self::isNestedValidation($value)) { $validation->addValidation(self::buildValidation($value, $key)); } else { $validation->addValidation(self::buildKeyValidation($value, $key)); } } return $validation; }
php
public static function buildValidation(array $schema, $name = null) { $validation = new NestedValidation($name); foreach ($schema as $key => $value) { if (!is_array($value)) { trigger_error('parsing error', E_USER_ERROR); } if (self::isNestedValidation($value)) { $validation->addValidation(self::buildValidation($value, $key)); } else { $validation->addValidation(self::buildKeyValidation($value, $key)); } } return $validation; }
[ "public", "static", "function", "buildValidation", "(", "array", "$", "schema", ",", "$", "name", "=", "null", ")", "{", "$", "validation", "=", "new", "NestedValidation", "(", "$", "name", ")", ";", "foreach", "(", "$", "schema", "as", "$", "key", "=>...
This function builds a validation acording to the specifgications of the json file @param array $schema @param null $name @return NestedValidation
[ "This", "function", "builds", "a", "validation", "acording", "to", "the", "specifgications", "of", "the", "json", "file" ]
e908e9598d806e7e5a8da5d46480137c474f93fb
https://github.com/ZimTis/array-validation/blob/e908e9598d806e7e5a8da5d46480137c474f93fb/src/ValidationBuilder.php#L29-L47
train
ZimTis/array-validation
src/ValidationBuilder.php
ValidationBuilder.isNestedValidation
private static function isNestedValidation(array $value) { return !(key_exists(Properties::TYPE, $value) && !is_array($value[Properties::TYPE])); }
php
private static function isNestedValidation(array $value) { return !(key_exists(Properties::TYPE, $value) && !is_array($value[Properties::TYPE])); }
[ "private", "static", "function", "isNestedValidation", "(", "array", "$", "value", ")", "{", "return", "!", "(", "key_exists", "(", "Properties", "::", "TYPE", ",", "$", "value", ")", "&&", "!", "is_array", "(", "$", "value", "[", "Properties", "::", "TY...
Check if the found value is a nestedValidation @param array $value @return boolean @see NestedValidation
[ "Check", "if", "the", "found", "value", "is", "a", "nestedValidation" ]
e908e9598d806e7e5a8da5d46480137c474f93fb
https://github.com/ZimTis/array-validation/blob/e908e9598d806e7e5a8da5d46480137c474f93fb/src/ValidationBuilder.php#L57-L60
train
ZimTis/array-validation
src/ValidationBuilder.php
ValidationBuilder.buildKeyValidation
public static function buildKeyValidation(array $options, $name) { if (!key_exists(Properties::TYPE, $options)) { trigger_error($name . ' must have a type'); } switch ($options[Properties::TYPE]) { case Types::STR: case Types::STRING: return new StringValidation($name, $options); case Types::INT: case Types::INTEGER: return new IntegerValidation($name, $options); case Types::FLOAT: return new FloatValidation($name, $options); case Types::BOOLEAN: return new BooleanValidation($name, $options); case Types::ARRY: return new ArrayValidation($name, $options); default: trigger_error(sprintf('%s is unknown', $options[Properties::TYPE]), E_USER_ERROR); } }
php
public static function buildKeyValidation(array $options, $name) { if (!key_exists(Properties::TYPE, $options)) { trigger_error($name . ' must have a type'); } switch ($options[Properties::TYPE]) { case Types::STR: case Types::STRING: return new StringValidation($name, $options); case Types::INT: case Types::INTEGER: return new IntegerValidation($name, $options); case Types::FLOAT: return new FloatValidation($name, $options); case Types::BOOLEAN: return new BooleanValidation($name, $options); case Types::ARRY: return new ArrayValidation($name, $options); default: trigger_error(sprintf('%s is unknown', $options[Properties::TYPE]), E_USER_ERROR); } }
[ "public", "static", "function", "buildKeyValidation", "(", "array", "$", "options", ",", "$", "name", ")", "{", "if", "(", "!", "key_exists", "(", "Properties", "::", "TYPE", ",", "$", "options", ")", ")", "{", "trigger_error", "(", "$", "name", ".", "...
Builds a KeyValidation @param array $options @param string $name @return \zimtis\arrayvalidation\validations\KeyValidation
[ "Builds", "a", "KeyValidation" ]
e908e9598d806e7e5a8da5d46480137c474f93fb
https://github.com/ZimTis/array-validation/blob/e908e9598d806e7e5a8da5d46480137c474f93fb/src/ValidationBuilder.php#L70-L92
train
sellerlabs/nucleus
src/SellerLabs/Nucleus/Support/Html.php
Html.escape
public static function escape($string) { Arguments::define( Boa::either( Boa::either( Boa::instance(SafeHtmlWrapper::class), Boa::instance(SafeHtmlProducerInterface::class) ), Boa::string() ) )->check($string); if ($string instanceof SafeHtmlWrapper) { return $string; } elseif ($string instanceof SafeHtmlProducerInterface) { $result = $string->getSafeHtml(); if ($result instanceof SafeHtmlWrapper) { return $result; } elseif ($result instanceof SafeHtmlProducerInterface) { return static::escape($result); } throw new CoreException(vsprintf( 'Object of class %s implements SafeHtmlProducerInterface' . ' but it returned an unsafe type: %s', [get_class($string), TypeHound::fetch($result)] )); } return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); }
php
public static function escape($string) { Arguments::define( Boa::either( Boa::either( Boa::instance(SafeHtmlWrapper::class), Boa::instance(SafeHtmlProducerInterface::class) ), Boa::string() ) )->check($string); if ($string instanceof SafeHtmlWrapper) { return $string; } elseif ($string instanceof SafeHtmlProducerInterface) { $result = $string->getSafeHtml(); if ($result instanceof SafeHtmlWrapper) { return $result; } elseif ($result instanceof SafeHtmlProducerInterface) { return static::escape($result); } throw new CoreException(vsprintf( 'Object of class %s implements SafeHtmlProducerInterface' . ' but it returned an unsafe type: %s', [get_class($string), TypeHound::fetch($result)] )); } return htmlspecialchars($string, ENT_QUOTES, 'UTF-8'); }
[ "public", "static", "function", "escape", "(", "$", "string", ")", "{", "Arguments", "::", "define", "(", "Boa", "::", "either", "(", "Boa", "::", "either", "(", "Boa", "::", "instance", "(", "SafeHtmlWrapper", "::", "class", ")", ",", "Boa", "::", "in...
Escape the provided string. @param SafeHtmlWrapper|SafeHtmlProducerInterface|string $string @throws CoreException @throws InvalidArgumentException @return SafeHtmlWrapper|string
[ "Escape", "the", "provided", "string", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Support/Html.php#L42-L73
train
clacy-builders/calendar-php
src/DateTime.php
DateTime.forceWorkday
public function forceWorkday($next = false) { $weekday = $this->format('N'); if ($weekday == 7) $this->addDays(1); elseif ($weekday == 6) $next ? $this->addDays(2) : $this->addDays(-1); return $this; }
php
public function forceWorkday($next = false) { $weekday = $this->format('N'); if ($weekday == 7) $this->addDays(1); elseif ($weekday == 6) $next ? $this->addDays(2) : $this->addDays(-1); return $this; }
[ "public", "function", "forceWorkday", "(", "$", "next", "=", "false", ")", "{", "$", "weekday", "=", "$", "this", "->", "format", "(", "'N'", ")", ";", "if", "(", "$", "weekday", "==", "7", ")", "$", "this", "->", "addDays", "(", "1", ")", ";", ...
Sets the current date to the nearest or next workday. Sunday always becomes monday. @param string $next if <code>true</code> saturday becomes monday, otherwise friday. @return DateTime
[ "Sets", "the", "current", "date", "to", "the", "nearest", "or", "next", "workday", "." ]
9e868c4fa37f6c81da0e7444a8e0da25cc6c9051
https://github.com/clacy-builders/calendar-php/blob/9e868c4fa37f6c81da0e7444a8e0da25cc6c9051/src/DateTime.php#L50-L56
train
clacy-builders/calendar-php
src/DateTime.php
DateTime.formatLocalized
public function formatLocalized($format, $encoding = 'UTF-8') { $str = strftime($format, $this->getTimestamp()); if ($encoding == 'UTF-8') { $str = utf8_encode($str); } return $str; }
php
public function formatLocalized($format, $encoding = 'UTF-8') { $str = strftime($format, $this->getTimestamp()); if ($encoding == 'UTF-8') { $str = utf8_encode($str); } return $str; }
[ "public", "function", "formatLocalized", "(", "$", "format", ",", "$", "encoding", "=", "'UTF-8'", ")", "{", "$", "str", "=", "strftime", "(", "$", "format", ",", "$", "this", "->", "getTimestamp", "(", ")", ")", ";", "if", "(", "$", "encoding", "=="...
Returns a string representation according to locale settings. @link http://php.net/manual/en/function.strftime.php @link http://php.net/manual/en/class.datetime.php @param string $format A format string containing specifiers like <code>%a</code>, <code>%B</code> etc. @param string $encoding For example 'UTF-8', 'ISO-8859-1'. @return string
[ "Returns", "a", "string", "representation", "according", "to", "locale", "settings", "." ]
9e868c4fa37f6c81da0e7444a8e0da25cc6c9051
https://github.com/clacy-builders/calendar-php/blob/9e868c4fa37f6c81da0e7444a8e0da25cc6c9051/src/DateTime.php#L69-L76
train
wasabi-cms/cms
src/Model/Table/MenusTable.php
MenusTable.getLinkTypes
public function getLinkTypes() { $event = new Event('Wasabi.Backend.MenuItems.getLinkTypes', $this); EventManager::instance()->dispatch($event); $typeExternal = ['type' => 'external']; $typeCustom = ['type' => 'custom']; $event->result[__d('wasabi_core', 'General')] = [ json_encode($typeExternal) => __d('wasabi_core', 'External Link'), json_encode($typeCustom) => __d('wasabi_core', 'Custom Controller Action') ]; return $event->result; }
php
public function getLinkTypes() { $event = new Event('Wasabi.Backend.MenuItems.getLinkTypes', $this); EventManager::instance()->dispatch($event); $typeExternal = ['type' => 'external']; $typeCustom = ['type' => 'custom']; $event->result[__d('wasabi_core', 'General')] = [ json_encode($typeExternal) => __d('wasabi_core', 'External Link'), json_encode($typeCustom) => __d('wasabi_core', 'Custom Controller Action') ]; return $event->result; }
[ "public", "function", "getLinkTypes", "(", ")", "{", "$", "event", "=", "new", "Event", "(", "'Wasabi.Backend.MenuItems.getLinkTypes'", ",", "$", "this", ")", ";", "EventManager", "::", "instance", "(", ")", "->", "dispatch", "(", "$", "event", ")", ";", "...
Get available link types via an Event trigger This fetches avilable Links from all activated Plugins. @return array
[ "Get", "available", "link", "types", "via", "an", "Event", "trigger", "This", "fetches", "avilable", "Links", "from", "all", "activated", "Plugins", "." ]
2787b6422ea1d719cf49951b3253fd0ac31d22ca
https://github.com/wasabi-cms/cms/blob/2787b6422ea1d719cf49951b3253fd0ac31d22ca/src/Model/Table/MenusTable.php#L75-L89
train
squire-assistant/dependency-injection
Definition.php
Definition.replaceArgument
public function replaceArgument($index, $argument) { if (0 === count($this->arguments)) { throw new OutOfBoundsException('Cannot replace arguments if none have been configured yet.'); } if ($index < 0 || $index > count($this->arguments) - 1) { throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1)); } $this->arguments[$index] = $argument; return $this; }
php
public function replaceArgument($index, $argument) { if (0 === count($this->arguments)) { throw new OutOfBoundsException('Cannot replace arguments if none have been configured yet.'); } if ($index < 0 || $index > count($this->arguments) - 1) { throw new OutOfBoundsException(sprintf('The index "%d" is not in the range [0, %d].', $index, count($this->arguments) - 1)); } $this->arguments[$index] = $argument; return $this; }
[ "public", "function", "replaceArgument", "(", "$", "index", ",", "$", "argument", ")", "{", "if", "(", "0", "===", "count", "(", "$", "this", "->", "arguments", ")", ")", "{", "throw", "new", "OutOfBoundsException", "(", "'Cannot replace arguments if none have...
Sets a specific argument. @param int $index @param mixed $argument @return $this @throws OutOfBoundsException When the replaced argument does not exist
[ "Sets", "a", "specific", "argument", "." ]
c61d77bf8814369344fd71b015d7238322126041
https://github.com/squire-assistant/dependency-injection/blob/c61d77bf8814369344fd71b015d7238322126041/Definition.php#L199-L212
train
jaredtking/jaqb
src/Statement/LimitStatement.php
LimitStatement.getLimit
public function getLimit() { if ($this->max > 0) { return min($this->max, $this->limit); } return $this->limit; }
php
public function getLimit() { if ($this->max > 0) { return min($this->max, $this->limit); } return $this->limit; }
[ "public", "function", "getLimit", "(", ")", "{", "if", "(", "$", "this", "->", "max", ">", "0", ")", "{", "return", "min", "(", "$", "this", "->", "max", ",", "$", "this", "->", "limit", ")", ";", "}", "return", "$", "this", "->", "limit", ";",...
Gets the limit. @return int
[ "Gets", "the", "limit", "." ]
04a853b530fcc12a9863349d3d0da6377d1b9995
https://github.com/jaredtking/jaqb/blob/04a853b530fcc12a9863349d3d0da6377d1b9995/src/Statement/LimitStatement.php#L72-L79
train
marando/phpSOFA
src/Marando/IAU/iauTaiut1.php
iauTaiut1.Taiut1
public static function Taiut1($tai1, $tai2, $dta, &$ut11, &$ut12) { $dtad; /* Result, safeguarding precision. */ $dtad = $dta / DAYSEC; if ($tai1 > $tai2) { $ut11 = $tai1; $ut12 = $tai2 + $dtad; } else { $ut11 = $tai1 + $dtad; $ut12 = $tai2; } /* Status (always OK). */ return 0; }
php
public static function Taiut1($tai1, $tai2, $dta, &$ut11, &$ut12) { $dtad; /* Result, safeguarding precision. */ $dtad = $dta / DAYSEC; if ($tai1 > $tai2) { $ut11 = $tai1; $ut12 = $tai2 + $dtad; } else { $ut11 = $tai1 + $dtad; $ut12 = $tai2; } /* Status (always OK). */ return 0; }
[ "public", "static", "function", "Taiut1", "(", "$", "tai1", ",", "$", "tai2", ",", "$", "dta", ",", "&", "$", "ut11", ",", "&", "$", "ut12", ")", "{", "$", "dtad", ";", "/* Result, safeguarding precision. */", "$", "dtad", "=", "$", "dta", "/", "DAYS...
- - - - - - - - - - i a u T a i u t 1 - - - - - - - - - - Time scale transformation: International Atomic Time, TAI, to Universal Time, UT1. This function is part of the International Astronomical Union's SOFA (Standards of Fundamental Astronomy) software collection. Status: canonical. Given: tai1,tai2 double TAI as a 2-part Julian Date dta double UT1-TAI in seconds Returned: ut11,ut12 double UT1 as a 2-part Julian Date Returned (function value): int status: 0 = OK Notes: 1) tai1+tai2 is Julian Date, apportioned in any convenient way between the two arguments, for example where tai1 is the Julian Day Number and tai2 is the fraction of a day. The returned UT11,UT12 follow suit. 2) The argument dta, i.e. UT1-TAI, is an observed quantity, and is available from IERS tabulations. Reference: Explanatory Supplement to the Astronomical Almanac, P. Kenneth Seidelmann (ed), University Science Books (1992) This revision: 2013 June 18 SOFA release 2015-02-09 Copyright (C) 2015 IAU SOFA Board. See notes at end.
[ "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "i", "a", "u", "T", "a", "i", "u", "t", "1", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-" ]
757fa49fe335ae1210eaa7735473fd4388b13f07
https://github.com/marando/phpSOFA/blob/757fa49fe335ae1210eaa7735473fd4388b13f07/src/Marando/IAU/iauTaiut1.php#L52-L68
train
10usb/css-lib
src/query/Specificity.php
Specificity.compare
public static function compare($left, $right){ if($left->a != $right->a) return $left->a <=> $right->a; if($left->b != $right->b) return $left->b <=> $right->b; if($left->c != $right->c) return $left->c <=> $right->c; if($left->i < 0 || $right->i < 0) return 0; return $left->i <=> $right->i; }
php
public static function compare($left, $right){ if($left->a != $right->a) return $left->a <=> $right->a; if($left->b != $right->b) return $left->b <=> $right->b; if($left->c != $right->c) return $left->c <=> $right->c; if($left->i < 0 || $right->i < 0) return 0; return $left->i <=> $right->i; }
[ "public", "static", "function", "compare", "(", "$", "left", ",", "$", "right", ")", "{", "if", "(", "$", "left", "->", "a", "!=", "$", "right", "->", "a", ")", "return", "$", "left", "->", "a", "<=>", "$", "right", "->", "a", ";", "if", "(", ...
Compares to specificities @param \csslib\query\Specificity $left @param \csslib\query\Specificity $right @return integer
[ "Compares", "to", "specificities" ]
6370b1404bae3eecb44c214ed4eaaf33113858dd
https://github.com/10usb/css-lib/blob/6370b1404bae3eecb44c214ed4eaaf33113858dd/src/query/Specificity.php#L40-L46
train
10usb/css-lib
src/query/Specificity.php
Specificity.get
public static function get($selector){ $specificity = $selector->hasNext() ? self::get($selector->getNext()) : new self(); if($selector->getIdentification()) $specificity->a++; if($selector->getClasses()) $specificity->b+= count($selector->getClasses()); if($selector->getAttributes()) $specificity->b+= count($selector->getAttributes()); if($selector->getPseudos()) $specificity->b+= count($selector->getPseudos()); if($selector->getTagName()) $specificity->c++; return $specificity; }
php
public static function get($selector){ $specificity = $selector->hasNext() ? self::get($selector->getNext()) : new self(); if($selector->getIdentification()) $specificity->a++; if($selector->getClasses()) $specificity->b+= count($selector->getClasses()); if($selector->getAttributes()) $specificity->b+= count($selector->getAttributes()); if($selector->getPseudos()) $specificity->b+= count($selector->getPseudos()); if($selector->getTagName()) $specificity->c++; return $specificity; }
[ "public", "static", "function", "get", "(", "$", "selector", ")", "{", "$", "specificity", "=", "$", "selector", "->", "hasNext", "(", ")", "?", "self", "::", "get", "(", "$", "selector", "->", "getNext", "(", ")", ")", ":", "new", "self", "(", ")"...
Calculated the specificity of a selector @param \csslib\Selector $selector @return \csslib\query\Specificity
[ "Calculated", "the", "specificity", "of", "a", "selector" ]
6370b1404bae3eecb44c214ed4eaaf33113858dd
https://github.com/10usb/css-lib/blob/6370b1404bae3eecb44c214ed4eaaf33113858dd/src/query/Specificity.php#L53-L63
train
EcomDev/phpspec-file-matcher
src/MatchLexer.php
MatchLexer.supports
public function supports($phrase, array $arguments) { if (!isset($this->forms[$phrase])) { return false; } $argumentMatch = $this->forms[$phrase]; if ($this->validateNoArgumentsCondition($arguments, $argumentMatch) || $this->validateStrictArgumentCountCondition($arguments, $argumentMatch)) { return false; } return true; }
php
public function supports($phrase, array $arguments) { if (!isset($this->forms[$phrase])) { return false; } $argumentMatch = $this->forms[$phrase]; if ($this->validateNoArgumentsCondition($arguments, $argumentMatch) || $this->validateStrictArgumentCountCondition($arguments, $argumentMatch)) { return false; } return true; }
[ "public", "function", "supports", "(", "$", "phrase", ",", "array", "$", "arguments", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "forms", "[", "$", "phrase", "]", ")", ")", "{", "return", "false", ";", "}", "$", "argumentMatch", "="...
Validates matcher condition based on specified rules @param string $phrase @param mixed[] $arguments @return bool
[ "Validates", "matcher", "condition", "based", "on", "specified", "rules" ]
5323bf833774c3d9d763bc01cdc7354a2985b47c
https://github.com/EcomDev/phpspec-file-matcher/blob/5323bf833774c3d9d763bc01cdc7354a2985b47c/src/MatchLexer.php#L46-L60
train
sasedev/extra-tools-bundle
src/Sasedev/ExtraToolsBundle/Command/UpdateTransCommand.php
UpdateTransCommand._crawlNode
private function _crawlNode(\Twig_Node $node) { if ($node instanceof TransNode && !$node->getNode('body') instanceof \Twig_Node_Expression_GetAttr) { // trans block $domain = $node->getNode('domain')->getAttribute('value'); $message = $node->getNode('body')->getAttribute('data'); $this->messages->set($message, $this->prefix . $message, $domain); } elseif ($node instanceof \Twig_Node_Print) { // trans filter (be carefull of how you chain your filters) $message = $this->_extractMessage($node->getNode('expr')); $domain = $this->_extractDomain($node->getNode('expr')); if ($message !== null && $domain !== null) { $this->messages->set($message, $this->prefix . $message, $domain); } } else { // continue crawling foreach ($node as $child) { if ($child != null) { $this->_crawlNode($child); } } } }
php
private function _crawlNode(\Twig_Node $node) { if ($node instanceof TransNode && !$node->getNode('body') instanceof \Twig_Node_Expression_GetAttr) { // trans block $domain = $node->getNode('domain')->getAttribute('value'); $message = $node->getNode('body')->getAttribute('data'); $this->messages->set($message, $this->prefix . $message, $domain); } elseif ($node instanceof \Twig_Node_Print) { // trans filter (be carefull of how you chain your filters) $message = $this->_extractMessage($node->getNode('expr')); $domain = $this->_extractDomain($node->getNode('expr')); if ($message !== null && $domain !== null) { $this->messages->set($message, $this->prefix . $message, $domain); } } else { // continue crawling foreach ($node as $child) { if ($child != null) { $this->_crawlNode($child); } } } }
[ "private", "function", "_crawlNode", "(", "\\", "Twig_Node", "$", "node", ")", "{", "if", "(", "$", "node", "instanceof", "TransNode", "&&", "!", "$", "node", "->", "getNode", "(", "'body'", ")", "instanceof", "\\", "Twig_Node_Expression_GetAttr", ")", "{", ...
Recursive function that extract trans message from a twig tree @param \Twig_Node The twig tree root
[ "Recursive", "function", "that", "extract", "trans", "message", "from", "a", "twig", "tree" ]
14037d6b5c8ba9520ffe33f26057e2e53bea7a75
https://github.com/sasedev/extra-tools-bundle/blob/14037d6b5c8ba9520ffe33f26057e2e53bea7a75/src/Sasedev/ExtraToolsBundle/Command/UpdateTransCommand.php#L184-L206
train
sasedev/extra-tools-bundle
src/Sasedev/ExtraToolsBundle/Command/UpdateTransCommand.php
UpdateTransCommand._extractMessage
private function _extractMessage(\Twig_Node $node) { if ($node->hasNode('node')) { return $this->_extractMessage($node->getNode('node')); } if ($node instanceof \Twig_Node_Expression_Constant) { return $node->getAttribute('value'); } return null; }
php
private function _extractMessage(\Twig_Node $node) { if ($node->hasNode('node')) { return $this->_extractMessage($node->getNode('node')); } if ($node instanceof \Twig_Node_Expression_Constant) { return $node->getAttribute('value'); } return null; }
[ "private", "function", "_extractMessage", "(", "\\", "Twig_Node", "$", "node", ")", "{", "if", "(", "$", "node", "->", "hasNode", "(", "'node'", ")", ")", "{", "return", "$", "this", "->", "_extractMessage", "(", "$", "node", "->", "getNode", "(", "'no...
Extract a message from a \Twig_Node_Print Return null if not a constant message @param \Twig_Node $node
[ "Extract", "a", "message", "from", "a", "\\", "Twig_Node_Print", "Return", "null", "if", "not", "a", "constant", "message" ]
14037d6b5c8ba9520ffe33f26057e2e53bea7a75
https://github.com/sasedev/extra-tools-bundle/blob/14037d6b5c8ba9520ffe33f26057e2e53bea7a75/src/Sasedev/ExtraToolsBundle/Command/UpdateTransCommand.php#L214-L224
train
sasedev/extra-tools-bundle
src/Sasedev/ExtraToolsBundle/Command/UpdateTransCommand.php
UpdateTransCommand._extractDomain
private function _extractDomain(\Twig_Node $node) { // must be a filter node if (!$node instanceof \Twig_Node_Expression_Filter) { return null; } // is a trans filter if ($node->getNode('filter')->getAttribute('value') == 'trans') { if ($node->getNode('arguments')->hasNode(1)) { return $node->getNode('arguments') ->getNode(1) ->getAttribute('value'); } else { return $this->defaultDomain; } } return $this->_extractDomain($node->getNode('node')); }
php
private function _extractDomain(\Twig_Node $node) { // must be a filter node if (!$node instanceof \Twig_Node_Expression_Filter) { return null; } // is a trans filter if ($node->getNode('filter')->getAttribute('value') == 'trans') { if ($node->getNode('arguments')->hasNode(1)) { return $node->getNode('arguments') ->getNode(1) ->getAttribute('value'); } else { return $this->defaultDomain; } } return $this->_extractDomain($node->getNode('node')); }
[ "private", "function", "_extractDomain", "(", "\\", "Twig_Node", "$", "node", ")", "{", "// must be a filter node", "if", "(", "!", "$", "node", "instanceof", "\\", "Twig_Node_Expression_Filter", ")", "{", "return", "null", ";", "}", "// is a trans filter", "if", ...
Extract a domain from a \Twig_Node_Print Return null if no trans filter @param \Twig_Node $node
[ "Extract", "a", "domain", "from", "a", "\\", "Twig_Node_Print", "Return", "null", "if", "no", "trans", "filter" ]
14037d6b5c8ba9520ffe33f26057e2e53bea7a75
https://github.com/sasedev/extra-tools-bundle/blob/14037d6b5c8ba9520ffe33f26057e2e53bea7a75/src/Sasedev/ExtraToolsBundle/Command/UpdateTransCommand.php#L232-L250
train
makinacorpus/drupal-udate
lib/Udate/CalendarEntityRowPlugin.php
Udate_CalendarEntityRowPlugin.preloadEntities
protected function preloadEntities($values) { $ids = array(); foreach ($values as $row) { $id = $row->{$this->field_alias}; if ($this->view->base_table == 'node_revision') { $this->entities[$id] = node_load(NULL, $id); } else { $ids[$id] = $id; } } $base_tables = date_views_base_tables(); $this->entity_type = $base_tables[$this->view->base_table]; if (!empty($ids)) { $this->entities = entity_load($this->entity_type, $ids); } }
php
protected function preloadEntities($values) { $ids = array(); foreach ($values as $row) { $id = $row->{$this->field_alias}; if ($this->view->base_table == 'node_revision') { $this->entities[$id] = node_load(NULL, $id); } else { $ids[$id] = $id; } } $base_tables = date_views_base_tables(); $this->entity_type = $base_tables[$this->view->base_table]; if (!empty($ids)) { $this->entities = entity_load($this->entity_type, $ids); } }
[ "protected", "function", "preloadEntities", "(", "$", "values", ")", "{", "$", "ids", "=", "array", "(", ")", ";", "foreach", "(", "$", "values", "as", "$", "row", ")", "{", "$", "id", "=", "$", "row", "->", "{", "$", "this", "->", "field_alias", ...
This actually was a good idea
[ "This", "actually", "was", "a", "good", "idea" ]
75f296acd7ba230b2d0a28c1fb906f4f1da863cf
https://github.com/makinacorpus/drupal-udate/blob/75f296acd7ba230b2d0a28c1fb906f4f1da863cf/lib/Udate/CalendarEntityRowPlugin.php#L16-L36
train
encorephp/view-controller
src/View/Style/StyleCollection.php
StyleCollection.addById
public function addById($id, array $styles) { $this->ids[$id] = array_merge_recursive($this->getById($id), $styles); }
php
public function addById($id, array $styles) { $this->ids[$id] = array_merge_recursive($this->getById($id), $styles); }
[ "public", "function", "addById", "(", "$", "id", ",", "array", "$", "styles", ")", "{", "$", "this", "->", "ids", "[", "$", "id", "]", "=", "array_merge_recursive", "(", "$", "this", "->", "getById", "(", "$", "id", ")", ",", "$", "styles", ")", ...
Add a style by ID @param string $id @param array $styles [description]
[ "Add", "a", "style", "by", "ID" ]
38335ee5c175364ea49bc378c141aabfe9fa3def
https://github.com/encorephp/view-controller/blob/38335ee5c175364ea49bc378c141aabfe9fa3def/src/View/Style/StyleCollection.php#L40-L43
train