sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
public function validate($attribute, $value, $parameters) { if ($parameters) { $this->dictionary->setDictionary($parameters); $this->badwords = $this->dictionary->getDictionary(); } return !$this->isProfane($value); }
Method to extends to Validator. @param string $attribute @param midex $value @param array $parameters @param \Illuminate\Contracts\Validation\Validator $validator [description] @return bool
entailment
public function addConnection($uriString) { if (!isset(self::$connectionList[$uriString])) { self::$connectionList[$uriString] = Factory::getDbRelationalInstance($uriString); if (self::$transaction) { self::$connectionList[$uriString]->beginTransaction(); ...
Add or reuse a connection @param $uriString @return \ByJG\AnyDataset\Db\DbDriverInterface
entailment
public function beginTransaction() { if (self::$transaction) { throw new TransactionException("Transaction Already Started"); } self::$transaction = true; foreach (self::$connectionList as $dbDriver) { $dbDriver->beginTransaction(); } }
Start a database transaction with the opened connections @throws \ByJG\MicroOrm\Exception\TransactionException
entailment
public function commitTransaction() { if (!self::$transaction) { throw new TransactionException("There is no Active Transaction"); } self::$transaction = false; foreach (self::$connectionList as $dbDriver) { $dbDriver->commitTransaction(); } }
Commit all open transactions @throws \ByJG\MicroOrm\Exception\TransactionException
entailment
public function rollbackTransaction() { if (!self::$transaction) { throw new TransactionException("There is no Active Transaction"); } self::$transaction = false; foreach (self::$connectionList as $dbDriver) { $dbDriver->rollbackTransaction(); } }
Rollback all open transactions @throws \ByJG\MicroOrm\Exception\TransactionException
entailment
public function destroy() { foreach (self::$connectionList as $dbDriver) { if (self::$transaction) { $dbDriver->commitTransaction(); } } self::$transaction = false; self::$connectionList = []; }
Destroy all connections
entailment
public function boot() { Storage::extend('gcs', function ($app, $config) { $adapterConfiguration = ['bucket' => $config['bucket']]; $serviceBuilderConfig = []; $optionalServiceBuilder = null; if (array_key_exists('project_id', $config) && false === empty($c...
{@inheritdoc}
entailment
public function register() { if ($this->isLumen() && !$this->app->has('filesystem')) { $this->app->singleton('filesystem', function ($app) { /** @var \Laravel\Lumen\Application $app */ return $app->loadComponent( 'filesystems', ...
Register bindings in the container. @return void
entailment
public function activate(Composer $composer, IOInterface $io) { // preload classes to prevent errors when removing the plugin class_exists(NpmBridge::class); class_exists(NpmBridgeFactory::class); class_exists(NpmClient::class); class_exists(NpmBridge::class); class_e...
Activate the plugin. @param Composer $composer The main Composer object. @param IOInterface $io The i/o interface to use.
entailment
public function onPostInstallCmd(Event $event) { $this->bridgeFactory->createBridge($event->getIO()) ->install($event->getComposer(), $event->isDevMode()); }
Handle post install command events. @param Event $event The event to handle. @throws NpmNotFoundException If the npm executable cannot be located. @throws NpmCommandFailedException If the operation fails.
entailment
public function onPostUpdateCmd(Event $event) { $this->bridgeFactory->createBridge($event->getIO()) ->update($event->getComposer()); }
Handle post update command events. @param Event $event The event to handle. @throws NpmNotFoundException If the npm executable cannot be located. @throws NpmCommandFailedException If the operation fails.
entailment
public function evaluate($expression) { $lexer = $this->getLexer(); $tokens = $lexer->tokenize($expression); $translationStrategy = new \Math\TranslationStrategy\ShuntingYard(); return $this->evaluateRPN($translationStrategy->translate($tokens)); }
Evaluate string representing mathematical expression. @param string $expression @return float
entailment
private function evaluateRPN(array $expressionTokens) { $stack = new \SplStack(); foreach ($expressionTokens as $token) { $tokenValue = $token->getValue(); if (is_numeric($tokenValue)) { $stack->push((float) $tokenValue); continue; ...
Evaluate array sequence of tokens in Reverse Polish notation (RPN) representing mathematical expression. @param array $expressionTokens @return float @throws \InvalidArgumentException
entailment
public static function checkCreditorIdentifier($ci) { $ci = preg_replace('/\s+/u', '', $ci); // remove whitespaces $ci = strtoupper($ci); // todo does this break the ci? if(!self::checkRestrictedPersonIdentifierSEPA($ci)) return false; $ciCopy = $ci;...
/* Checks if an creditor identifier (ci) is valid. Note that also if the ci is valid it does not have to exist @param string $ci @return string|false The valid iban or false if it is not valid
entailment
public static function checkIBAN($iban, $options = null) { $iban = preg_replace('/\s+/u', '' , $iban ); // remove whitespaces $iban = strtoupper($iban); if(!preg_match('/^' . self::PATTERN_IBAN . '$/',$iban)) return false; $ibanCopy = $iban; if(!isset($opti...
Checks if an iban is valid. Note that also if the iban is valid it does not have to exist @param string $iban @param array $options valid keys: - checkByCheckSum (boolean): If true, the IBAN checksum is calculated (default:true) - checkByFormat (boolean): If true, the format is checked by regular expression (default:...
entailment
public static function checkBIC($bic, array $options = null) { $bic = preg_replace('/\s+/u', '' , $bic ); // remove whitespaces if(!empty($options['forceLongBic']) && strlen($bic) === 8) $bic .= empty($options['forceLongBicStr']) ? 'XXX' : $options['forceLongBicStr']; if(empt...
Checks if a bic is valid. Note that also if the bic is valid it does not have to exist @param string $bic @param array $options Takes the following keys: - `allowEmptyBic`: (bool) The BIC can be empty. - `forceLongBic`: (bool) If the BIC has exact 8 characters, `forceLongBicStr` is added. (default false) - `forceLong...
entailment
public static function isNationalTransaction($iban1, $iban2) { // remove whitespaces $iban1 = preg_replace('#\s+#','',$iban1); $iban2 = preg_replace('#\s+#','',$iban2); // check the country code if(stripos($iban1,substr($iban2,0,2)) === 0) return true; el...
Checks if both IBANs do belong to the same country. This function does not check if the IBANs are valid. @param string $iban1 @param string $iban2 @return bool
entailment
public static function isEEATransaction($iban1, $iban2) { // remove whitespaces $iban1 = preg_replace('#\s+#','',$iban1); $iban2 = preg_replace('#\s+#','',$iban2); // check if both county codes belong to the EEA $EEA = ['IS' => 1, 'LI' => 1, 'NO' => 1, 'BE' => 1, 'BG' => 1, ...
Checks if both IBANs belong to the EEA (European Economic Area) This function does not check if the IBANs are valid. @param string $iban1 @param string $iban2 @return bool
entailment
public static function crossCheckIbanBic($iban, $bic) { // check for special cases if(in_array(strtoupper($bic), self::$exceptionalBics)) return true; // remove whitespaces $iban = preg_replace('#\s+#','',$iban); $bic = preg_replace('#\s+#','',$bic); //...
Checks if IBAN and BIC belong to the same country. If not, they also can not belong to each other. @param string $iban @param string $bic @return bool
entailment
public static function sanitizeDateFormat($input, array $preferredFormats = []) { $dateFormats = ['d.m.Y', 'd.m.y', 'j.n.Y', 'j.n.y', 'm.d.Y', 'm.d.y', 'n.j.Y', 'n.j.y', 'Y/m/d', 'y/m/d', 'Y/n/j', 'y/n/j', 'Y.m.d', 'y.m.d', 'Y.n.j', 'y.n.j']; // input is already in the corre...
Tries to convert the given date into the format YYYY-MM-DD (Y-m-d). Therefor it tries the following input formats in the order of appearance: d.m.Y, d.m.y, j.n.Y, j.n.y, m.d.Y, m.d.y, n.j.Y, n.j.y, Y/m/d, y/m/d, Y/n/j, y/n/j, Y.m.d, y.m.d, Y.n.j, y.n.j. Notice that this method tries to interpret the first number as day...
entailment
public static function checkCreateDateTime($input) { $dateObj = \DateTime::createFromFormat('Y-m-d\TH:i:s', $input); if($dateObj !== false && $input === $dateObj->format('Y-m-d\TH:i:s')) return $input; else return false; }
Checks if the input has the format 'Y-m-d\TH:i:s' @param string $input @return string|false Returns $input if it is valid and false else.
entailment
public static function getDate($date = null, $inputFormat = 'd.m.Y') { if(empty($date)) $dateTimeObj = new \DateTime(); else $dateTimeObj = \DateTime::createFromFormat($inputFormat, $date); if($dateTimeObj === false) return false; return $dateTim...
Reformat a date string from a given format to the ISODate format. Notice: 20.13.2014 is valid and becomes 2015-01-20. @param string $date A date string of the given input format @param string $inputFormat default is the german format DD.MM.YYYY @return string|false date as YYYY-MM-DD or false, if the input is not a da...
entailment
public static function getDateWithOffset($workdayOffset, $today = null, $inputFormat = 'd.m.Y') { if(empty($today)) $dateTimeObj = new \DateTime(); else $dateTimeObj = \DateTime::createFromFormat($inputFormat, $today); if($dateTimeObj === false) return fa...
Computes the next TARGET2 day (including today) with respect to a TARGET2 offset. @param int $workdayOffset a positive number of workdays to skip. @param string $today if set, this date is used as today @param string $inputFormat @return string|false YYYY-MM-DD
entailment
public static function getDateWithMinOffsetFromToday($target, $workdayMinOffset, $inputFormat = 'd.m.Y', $today = null) { $targetDateObj = \DateTime::createFromFormat($inputFormat,$target); $earliestDate = self::getDateWithOffset($workdayMinOffset, $today, $inputFormat); if($targetDateObj ...
Returns the target date, if it has at least the given offset of TARGET2 days form today. Else the earliest date that respects the offset is returned. @param string $target @param int $workdayMinOffset @param string $inputFormat @param string $today @return string
entailment
private static function dateIsTargetDay(\DateTime $date) { // $date is a saturday or sunday? if($date->format('N') === '6' || $date->format('N') === '7') return false; $day = $date->format('m-d'); if($day === '01-01' // new year's day || $day === ...
Checks if $date is a SEPA TARGET day. Every day is a TARGET day except for saturdays, sundays new year's day, good friday, easter monday, the may holiday, first and second christmas holiday. @param \DateTime $date @return bool
entailment
public static function check($field, $input, array $options = null, $version = null) { $field = strtolower($field); switch($field) // fall-through's are on purpose { case 'orgnlcdtrschmeid_id': case 'ci': return self::checkCreditorIdentifier($input); ...
Checks if the input holds for the field. @param string $field Valid fields are: 'orgnlcdtrschmeid_id','ci','msgid','pmtid','pmtinfid', 'orgnlmndtid','mndtid','initgpty','cdtr','dbtr','orgnlcdtrschmeid_nm', 'ultmtcdrt','ultmtdebtr','rmtinf','orgnldbtracct_iban','iban','bic', 'ccy','amendment', 'btchbookg','instdamt',...
entailment
public static function checkInput($field, array &$inputArray, $inputKeys, array $options = null) { $value = self::getValFromMultiDimInput($inputArray,$inputKeys); if($value === false) return false; else return self::check($field,$value,$options); }
This function checks if the index of the inputArray exists and if the input is valid. The function can be called as `checkInput($fieldName,$_POST,['input',$fieldName],$options)` and equals `check($fieldName,$_POST['input'][$fieldName],$options)`, but checks first, if the index exists. @param string $field see `chec...
entailment
public static function sanitizeInput($field, array &$inputArray, $inputKeys, $flags = 0) { $value = self::getValFromMultiDimInput($inputArray,$inputKeys); if($value === false) return false; else return self::sanitize($field,$value,$flags); }
This function checks if the index of the inputArray exists and if the input is valid. The function can be called as `sanitizeInput($fieldName,$_POST,['input',$fieldName],$flags)` and equals `sanitize($fieldName,$_POST['input'][$fieldName],$flags)`, but checks first, if the index exists. @param string $field see `sa...
entailment
public static function checkAndSanitize($field, $input, $flags = 0, array $options = null) { $checkedInput = self::check($field, $input, $options); if($checkedInput !== false) return $checkedInput; return self::sanitize($field,$input,$flags); }
Checks the input and if it is not valid it tries to sanitize it. @param string $field all fields check and/or sanitize supports @param mixed $input @param int $flags see `sanitize()` for details @param array $options see `check()` for details @return mixed|false
entailment
public static function checkAndSanitizeInput($field, array &$inputArray, $inputKeys, $flags = 0, array $options = null) { $value = self::getValFromMultiDimInput($inputArray,$inputKeys); if($value === false) return false; else return self::checkAndSanitize($field,$val...
This function checks if the index of the inputArray exists and if the input is valid. The function can be called as `checkAndSanitizeInput($fieldName,$_POST,['input',$fieldName],$flags,$options)` and equals `checkAndSanitize($fieldName,$_POST['input'][$fieldName],$flags,$options)`, but checks first, if the index exists...
entailment
public static function sanitize($field, $input, $flags = 0) { $field = strtolower($field); switch($field) // fall-through's are on purpose { case 'orgid_id': return self::sanitizeText(self::TEXT_LENGTH_VERY_SHORT, $input, true, $flags); case '...
Tries to sanitize the the input so it fits in the field. @param string $field Valid fields are: 'ultmtcdrt', 'ultmtdebtr', 'orgnlcdtrschmeid_nm', 'initgpty', 'cdtr', 'dbtr', 'rmtinf' @param mixed $input @param int $flags Flags used in replaceSpecialChars() @return mixed|false The sanitized input or false if the in...
entailment
public static function containsAllKeys(array $arr, array $keys) { foreach($keys as $key) { if( !isset( $arr[$key] ) ) return false; } return true; }
Checks if $arr misses one of the given $keys @param array $arr @param array $keys @return bool false, if at least one key is missing, else true
entailment
public static function containsNotAnyKey(array $arr, array $keys) { foreach ($keys as $key) { if (isset($arr[$key])) return false; } return true; }
Checks if $arr not contains any key of $keys @param array $arr @param array $keys @return bool true, if $arr contains not even on the the keys, else false
entailment
private static function checkBoolean($input ) { $bbi = filter_var($input,FILTER_VALIDATE_BOOLEAN,FILTER_NULL_ON_FAILURE); if($bbi === true) return 'true'; if($bbi === false) return 'false'; return false; }
Checks if $bbi is a valid batch booking indicator. Returns 'true' for "1", "true", "on" and "yes", returns 'false' for "0", "false", "off", "no", and "" @param mixed $input @return string|false The batch booking indicator (in lower case only) or false if not valid
entailment
public static function sanitizeLength($input, $maxLen) { if(isset($input[$maxLen])) // take string as array of chars return substr($input,0,$maxLen); else return $input; }
Shortens the input string to the max length if it is to long. @param string $input @param int $maxLen @return string sanitized string
entailment
public static function replaceSpecialChars($str, $flags = 0) { if($flags === 0) { $specialCharsReplacement =& self::$specialCharsReplacement; // reference $charExceptions = ''; } else { $specialCharsReplacement = self::$specialCharsReplacem...
Replaces all special chars like á, ä, â, à, å, ã, æ, Ç, Ø, Š, ", ’ and & by a latin character. All special characters that cannot be replaced by a latin char (such like quotes) will be removed as long as they cannot be converted. See http://www.europeanpaymentscouncil.eu/index.cfm/knowledge-bank/epc-documents/sepa-requ...
entailment
private static function checkAmountFormat( $amount ) { // $amount is a string -> check for '1,234.56' $result = filter_var($amount, FILTER_VALIDATE_FLOAT, FILTER_FLAG_ALLOW_THOUSAND); if($result === false) $result = filter_var(strtr($amount, [',' => '.', '.' => ',']), FILTER_VAL...
Checks if the amount fits the format: A float with only two decimals, not lower than 0.01, not greater than 999,999,999.99. @param mixed $amount float or string with or without thousand separator (use , or .). You can use '.' or ',' as decimal point, but not one sign as thousand separator and decimal point. So 1234.56...
entailment
private static function checkSeqType($seqTp) { $seqTp = strtoupper($seqTp); if( in_array($seqTp, [self::SEQUENCE_TYPE_FIRST, self::SEQUENCE_TYPE_RECURRING, self::SEQUENCE_TYPE_ONCE, self::SEQUENCE_TYPE_FINAL]) ) return $seqTp; return false; }
Checks if the sequence type is valid. @param string $seqTp @return string|false
entailment
public static function version2string($version) { switch($version) { // fall-through's are on purpose case self::SEPA_PAIN_001_001_03_GBIC: case self::SEPA_PAIN_001_001_03: return 'pain.001.001.03'; case self::SEPA_PAIN_001_002_03: return 'pain.001.002.03'; ...
Returns the SEPA file version as a string. @param int $version Use the SEPA_PAIN_* constants. @return string|false SEPA file version as a string or false if the version is invalid.
entailment
public function load(array $configs, ContainerBuilder $container) { $configuration = new FlowConfiguration(); $processor = new Processor(); $this->flowsConfig = $processor->processConfiguration($configuration, $configs); }
Loads a specific configuration. @param array $configs @param ContainerBuilder $container
entailment
public function process(ContainerBuilder $container) { $definition = $container->findDefinition(FlowManager::class); foreach ($this->flowsConfig as $flowTube => $flowConfigData) { $flowConfig = new FlowConfig($flowTube, $flowConfigData); $flowDefinition = new Definition(Flow:...
You can modify the container here before it is dumped to PHP code.
entailment
public function getClassName() { $adapter = $this->getAdapter(); if ($adapter) { return $adapter; } return ucfirst($this->dsn->scheme); }
getClassName Return the adapter if there is one, else return the scheme @return string
entailment
public function createBridge(IOInterface $io): NpmBridge { return new NpmBridge($io, $this->vendorFinder, $this->client); }
Construct a new Composer NPM bridge plugin. @param IOInterface $io The i/o interface to use.
entailment
public function getEscapedString() { if ($this->escapedString === null) { $this->escapedString = str_replace('-', ' ', $this->escape($this->getRawString())); $this->escapedString = preg_replace(['/\s+([0-9])/','/\s+/'], ['$1', ' '], $this->escapedString); } return $th...
Remove spaces before numbers in order to avoid search errors Remove all dashes @return string
entailment
public static function escape ($string) { if (!is_numeric($string)) { if (preg_match('/\W/', $string) == 1) { // multiple words $stringLength = strlen($string); if ($string{0} == '"' && $string{$stringLength - 1} == '"') { // p...
Quote and escape search strings @param string $string String to escape @return string The escaped/quoted string
entailment
public static function parse($url) { $scheme = substr($url, 0, strpos($url, ':')); if (strpos($scheme, '+')) { $scheme = substr($scheme, 0, strpos($scheme, '+')); } if (!$scheme) { throw new \Exception(sprintf('The url \'%s\' could not be parsed', $url)); ...
parse a dsn string into a dsn instance If a more specific dsn class is available an instance of that class is returned @param string $url @return mixed Dsn instance or false
entailment
public static function map($scheme = null, $class = null) { if (is_array($scheme)) { foreach ($scheme as $s => $class) { static::map($s, $class); } return static::$schemeMap; } if ($scheme === null) { return static::$schemeMap;...
Read or change the scheme map For example: $true = Dsn::map('foo', '\My\Dsn\Class'); $classname = Dsn::map('foo'); $true = Dsn::map('foo', false); // Remove foo from the map $fullMap = Dsn::map(); $false = Dsn::map('unknown'); $array = ['this' => 'That\Class', 'other' => 'Other\Class', ...]; $fullMap = Dsn::map($a...
entailment
public function defaultPort($port = null) { if (!is_null($port)) { $this->defaultPort = (int)$port; if ($this->url['port'] === null) { $this->url['port'] = $this->defaultPort; } } return $this->defaultPort; }
Get or set the default port @param int $port @return int
entailment
public function parseUrl($string) { $this->url = []; $url = parse_url($string); if (!$url || !isset($url['scheme'])) { throw new \Exception(sprintf('The url \'%s\' could not be parsed', $string)); } $this->parseUrlArray($url); }
parseUrl Parse a url and merge with any extra get arguments defined @param string $string @return void
entailment
protected function parseUrlArray($url) { if (strpos($url['scheme'], '+')) { list($url['scheme'], $url['adapter']) = explode('+', $url['scheme']); } $defaultPort = $this->defaultPort(); if ($defaultPort && empty($url['port'])) { $url['port'] = $defaultPort; ...
Worker function for parseUrl Take the passed array, and using getters update the instance @param array $url @return void
entailment
public function toArray() { $url = $this->url; $return = []; foreach (array_keys($url) as $key) { $getter = 'get' . ucfirst($key); $val = $this->$getter(); if ($val !== null) { $return[$key] = $val; } } return...
toArray Return this instance as an associative array using getter methods if they exist @return array
entailment
protected function toUrlArray($data) { $url = array_intersect_key($data, $this->uriKeys); foreach (['host', 'user', 'pass'] as $key) { if (!isset($url[$key])) { continue; } $url[$key] = urlencode($url[$key]); } if ($url['adapter'...
Worker function for toUrl - does not rely on instance state @param array $data @return string
entailment
protected function readDictionary($dictionary) { $words = []; $baseDictPath = $this->getBaseDictPath(); if (is_array($dictionary)) { foreach ($dictionary as $file) { if (file_exists($baseDictPath.$file.'.php')) { $dict = include $baseDictPath.$...
[readDictionary description]. @param [type] $dictionary [description] @return [type] [description]
entailment
protected function _addFilter($facetName, $value) { if (isset($this->filters[$facetName])) { $currentValue = $this->filters[$facetName]; if (!is_array($currentValue)) { $currentValue = array($currentValue); } $currentValue[] = $value; ...
Add new filter without overwriting existing filters @param string $facetName @param string|int $value
entailment
private function isValidAttributeFilterValue($value) { if (is_array($value)) { foreach ($value as $subValue) { if (!$this->isValidAttributeFilterValue($subValue)) { return false; } } return true; } retur...
Value must be an option ID or an array of option IDs @param mixed $value @return bool
entailment
public static function studlyCase($string) { $string = Strings::capitalize(Strings::replace($string, ['/-/', '/_/'], ' ')); return Strings::replace($string, '/ /'); }
Converts the given string to `StudlyCase` @param string $string @return string
entailment
public static function spinalCase($string) { /** RegExp source http://stackoverflow.com/a/1993772 */ preg_match_all('/([A-Z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)/', $string, $matches); $matches = $matches[0]; foreach ($matches as &$match) { $match = ($match == Strings::upper($match)) ? S...
Converts the given string to `spinal-case` @param string $string @return string
entailment
public function getTransport() { $adapter = $this->getAdapter(); if ($adapter) { return $adapter; } return ucfirst($this->dsn->scheme); }
getTransport Return the adapter if there is one, else return the scheme @return string
entailment
public function appendService(ServiceBase $successor) { if ($this->successor !== null) { $this->successor->appendService($successor); } else { $this->successor = $successor; } }
Append service to chain of responsibility @param ServiceBase $successor
entailment
protected function _constructBaseUrl($servlet, $params = array()) { if (count($params)) { //escape all parameters appropriately for inclusion in the query string $escapedParams = array(); foreach ($params as $key => $value) { $escapedP...
Return a valid http URL given this server's host, port and path and a provided servlet name Exclude core name from @param string $servlet @param array $params @return string @throws Exception
entailment
public function swapCores($core, $otherCore, $method = self::METHOD_GET) { if (!$this->_coresUrl) { throw new Exception('Please call "setBasePath" before.'); } $params = array(); // construct our full parameters $params['action'] = 'SWAP'; $params['core'...
core swap interface @param string $core @param string $otherCore @param string $method The HTTP method (Service::METHOD_GET or Service::METHOD::POST) @return Apache_Solr_Response @throws Apache_Solr_HttpTransportException If an error occurs during the service call @throws Apache_Solr_InvalidArgumentException If an in...
entailment
public function info($method = self::METHOD_GET) { if (!$this->_infoUrl) { throw new Exception('Please call "setBasePath" before.'); } $params = array(); // construct our full parameters $params['wt'] = 'json'; $queryString = $this->_generateQueryString...
admin info interface @param string $method The HTTP method (Service::METHOD_GET or Service::METHOD::POST) @return Apache_Solr_Response @throws Apache_Solr_HttpTransportException If an error occurs during the service call @throws Apache_Solr_InvalidArgumentException If an invalid HTTP method is used @throws Exception
entailment
public function exclude(array $names) { $filtered = clone $this; foreach ($names as $name) { unset($filtered[$name]); } return $filtered; }
Returns new collection without the given field names @param string[] $names @return ApacheSolrFacetCollection
entailment
public function match(IRequest $httpRequest) { $url = $httpRequest->getUrl(); $basePath = Strings::replace($url->getBasePath(), '/\//', '\/'); $cleanPath = Strings::replace($url->getPath(), "/^{$basePath}/"); $path = Strings::replace($this->getPath(), '/\//', '\/'); $pathRexExp = empty($path) ? "/^...
Maps HTTP request to a Request object. @param \Nette\Http\IRequest $httpRequest @return \Nette\Application\Request|NULL
entailment
public function constructUrl(Request $appRequest, Url $refUrl) { // Module prefix not match. if($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) { return NULL; } $parameters = $appRequest->getParameters(); $url = $refUrl->getBaseUrl(); $urlStack = [];...
Constructs absolute URL from Request object. @param \Nette\Application\Request $appRequest @param \Nette\Http\Url $refUrl @throws \Nette\InvalidStateException @return string|NULL
entailment
public function hasLowerPriority(Operator $o) { $hasLowerPriority = ((Operator::O_LEFT_ASSOCIATIVE == $o->getAssociativity() && $this->getPriority() == $o->getPriority()) || $this->getPriority() < $o->getPriority()); return $hasLowerPriority;...
Return true if this operator has lower priority of operator $o. @param \Math\Operator $o @return boolean
entailment
public function install(Composer $composer, bool $isDevMode = true) { $this->io->write( '<info>Installing NPM dependencies for root project</info>' ); $package = $composer->getPackage(); if ($this->isDependantPackage($package, $isDevMode)) { $isNpmAvailable ...
Install NPM dependencies for a Composer project and its dependencies. @param Composer $composer The main Composer object. @param bool $isDevMode True if dev mode is enabled. @throws NpmNotFoundException If the npm executable cannot be located. @throws NpmCommandFailedException If the operation fails.
entailment
public function update(Composer $composer) { $this->io->write( '<info>Updating NPM dependencies for root project</info>' ); $package = $composer->getPackage(); if ($this->isDependantPackage($package, true)) { $timeout = $this->packageTimeout($package->getExt...
Update NPM dependencies for a Composer project and its dependencies. @param Composer $composer The main Composer object. @throws NpmNotFoundException If the npm executable cannot be located. @throws NpmCommandFailedException If the operation fails.
entailment
public function isDependantPackage( PackageInterface $package, bool $includeDevDependencies = false ): bool { foreach ($package->getRequires() as $link) { if ('eloquent/composer-npm-bridge' === $link->getTarget()) { return true; } } if...
Returns true if the supplied package requires the Composer NPM bridge. @param PackageInterface $package The package to inspect. @param bool $includeDevDependencies True if the dev dependencies should also be inspected. @return bool True if the package requires the bridge.
entailment
public function setPath($path) { if (!$this->databaseIsPath) { $path = ltrim($path, '/'); } $this->setDatabase($path); }
setPath @param string $path @return void
entailment
public function parseUrl($string) { $engine = null; if ($this->databaseIsPath) { $engine = substr($string, 0, strpos($string, ':')); $string = 'file' . substr($string, strlen($engine)); } parent::parseUrl($string); if ($engine !== null) { ...
parseUrl Handle the parent method only dealing with paths for the file scheme @param string $string @return array
entailment
public function toUrl() { $url = $this->url; unset($url['engine'], $url['database']); $url['scheme'] = $this->getScheme(); $url['path'] = $this->getPath(); return $this->toUrlArray($url); }
return this instance as a dsn url string @return string
entailment
public static function containsCaseless($haystack, $needles) { foreach ((array) $needles as $needle) { $needle = preg_quote($needle); if ($needle != '' && preg_match("/$needle/iu", $haystack)) { return true; } } return false; }
Taken from Illuminate\Support\Str Determine if a given string contains a given word with case insensitive match. @param string $haystack @param string|array $needles @return bool
entailment
public static function removeAccent($string) { $replace = [ 'ъ'=> '-', 'Ь'=>'-', 'Ъ'=>'-', 'ь'=>'-', 'Ă'=> 'A', 'Ą'=>'A', 'À'=>'A', 'Ã'=>'A', 'Á'=>'A', 'Æ'=>'A', 'Â'=>'A', 'Å'=>'A', 'Ä'=>'Ae', 'Þ'=> 'B', 'Ć'=> 'C', 'ץ'=>'C', 'Ç'=>'C', 'È'=> 'E', 'Ę...
Remove accents or special characters from a string. @param string $string @return string
entailment
public function getServerInfo() { return sprintf('%s:%s%s%s', $this->host, $this->port, $this->path, $this->core); }
Return unique resource identifier for solr core @return string
entailment
public function __isset($key) { if (!$this->_isParsed) { $this->_parseData(); $this->_isParsed = true; } return isset($this->_parsedData->$key); }
Magic function for isset function on parsed data @param string $key @return boolean
entailment
protected function _parseData() { //An alternative would be to use Zend_Json::decode(...) $data = json_decode($this->_response->getBody()); // check that we receive a valid JSON response - we should never receive a null if ($data === null) { throw new Apache_Solr_ParserException('Solr response does not a...
Parse the raw response into the parsed_data array for access @throws Apache_Solr_ParserException If the data could not be parsed
entailment
public static function build($array, Closure $callback) { $results = array(); foreach ($array as $key => $value) { list($innerKey, $innerValue) = call_user_func($callback, $key, $value); $results[$innerKey] = $innerValue; } return $results; }
Build a new array using a callback. @param array $array @param \Closure $callback @return array
entailment
public function tokenize($code) { $code = trim((string) $code); if (empty($code)) { throw new \InvalidArgumentException('Cannot tokenize empty string.'); } $this->code = $code; $this->tokens = array(); $tokenArray = explode(' ', $this->code); if...
Tokenize matematical expression. @param type $code @return array Collection of Token instances @throws \InvalidArgumentException
entailment
public function getDatasource() { $adapter = $this->getAdapter(); if ($adapter) { return $adapter; } $engine = $this->dsn->engine; return 'Database/' . ucfirst($engine); }
getDatasource Get the engine to use for this dsn. Defaults to `Database/Enginename` @return string
entailment
public function flush() { if (!empty($this->documents)) { $this->resource->addDocuments($this->storeId, $this->documents); $this->clearDocuments(); } }
Commit previously added documents to Solr and clear queue @return void
entailment
public static function getDefaultStatusMessage($statusCode) { $statusCode = (int) $statusCode; if (isset(self::$_defaultStatusMessages[$statusCode])) { return self::$_defaultStatusMessages[$statusCode]; } return "Unknown Status"; }
Get the HTTP status message based on status code @return string
entailment
public function publish(Message $message) { // Check if required message parameters are set if (!$message->getShortMessage() || !$message->getHost()) { throw new \UnexpectedValueException( 'Missing required data parameter: "version", "short_message" and "host" are required....
Publishes a Message, returns false if an error occured during write @throws \UnexpectedValueException @param Message $message @return boolean
entailment
protected function _constructUrl($servlet, $params = array()) { if (count($params)) { //escape all parameters appropriately for inclusion in the query string $escapedParams = array(); foreach ($params as $key => $value) { $escapedParams[] = urlencode($key) . '=' . urlencode($value); } $quer...
Return a valid http URL given this server's host, port and path and a provided servlet name @param string $servlet @return string
entailment
protected function _initUrls() { //Initialize our full servlet URLs now that we have server information $this->_extractUrl = $this->_constructUrl(self::EXTRACT_SERVLET); $this->_pingUrl = $this->_constructUrl(self::PING_SERVLET); $this->_searchUrl = $this->_constructUrl(self::SEARCH_SERVLET); $this->_systemU...
Construct the Full URLs for the three servlets we reference
entailment
protected function _sendRawGet($url, $timeout = FALSE) { $httpTransport = $this->getHttpTransport(); $httpResponse = $httpTransport->performGetRequest($url, $timeout); $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays); if ($solrResponse->getHt...
Central method for making a get operation against this Solr Server @param string $url @param float $timeout Read timeout in seconds @return Apache_Solr_Response @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
entailment
protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') { $httpTransport = $this->getHttpTransport(); $httpResponse = $httpTransport->performPostRequest($url, $rawPost, $contentType, $timeout); $solrResponse = new Apache_Solr_Response($httpResponse, $this->_cr...
Central method for making a post operation against this Solr Server @param string $url @param string $rawPost @param float $timeout Read timeout in seconds @param string $contentType @return Apache_Solr_Response @throws Apache_Solr_HttpTransportException If a non 200 response status is returned
entailment
public function setHost($host) { //Use the provided host or use the default if (empty($host)) { throw new Apache_Solr_InvalidArgumentException('Host parameter is empty'); } else { $this->_host = $host; } if ($this->_urlsInited) { $this->_initUrls(); } }
Set the host used. If empty will fallback to constants @param string $host @throws Apache_Solr_InvalidArgumentException If the host parameter is empty
entailment
public function setPort($port) { //Use the provided port or use the default $port = (int) $port; if ($port <= 0) { throw new Apache_Solr_InvalidArgumentException('Port is not a valid port number'); } else { $this->_port = $port; } if ($this->_urlsInited) { $this->_initUrls(); } }
Set the port used. If empty will fallback to constants @param integer $port @throws Apache_Solr_InvalidArgumentException If the port parameter is empty
entailment
public function setPath($path) { $path = trim($path, '/'); if (strlen($path) > 0) { $this->_path = '/' . $path . '/'; } else { $this->_path = '/'; } if ($this->_urlsInited) { $this->_initUrls(); } }
Set the path used. If empty will fallback to constants @param string $path
entailment
public function setNamedListTreatment($namedListTreatment) { switch ((string) $namedListTreatment) { case Apache_Solr_Service::NAMED_LIST_FLAT: $this->_namedListTreatment = Apache_Solr_Service::NAMED_LIST_FLAT; break; case Apache_Solr_Service::NAMED_LIST_MAP: $this->_namedListTreatment = Apache_...
Set how NamedLists should be formatted in the response data. This mainly effects the facet counts format. @param string $namedListTreatment @throws Apache_Solr_InvalidArgumentException If invalid option is set
entailment
public function ping($timeout = 2) { $start = microtime(true); $httpTransport = $this->getHttpTransport(); $httpResponse = $httpTransport->performHeadRequest($this->_pingUrl, $timeout); $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays); i...
Call the /admin/ping servlet, can be used to quickly tell if a connection to the server is able to be made. @param float $timeout maximum time to wait for ping in seconds, -1 for unlimited (default is 2) @return float Actual time taken to ping the server, FALSE if timeout or HTTP error status occurs
entailment
public function addDocument(Apache_Solr_Document $document, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0) { $documentXmlFragment = $this->_documentToXmlFragment($document); return $this->addRawDocuments( $documentXmlFragment, $allowDups, $overwritePending, ...
Add a Solr Document to the index @param Apache_Solr_Document $document @param boolean $allowDups @param boolean $overwritePending @param boolean $overwriteCommitted @param integer $commitWithin The number of milliseconds that a document must be committed within, see @{link http://wiki.apache.org/solr/UpdateXmlMessages...
entailment
public function addDocuments($documents, $allowDups = false, $overwritePending = true, $overwriteCommitted = true, $commitWithin = 0) { $documentsXmlFragment = ''; foreach ($documents as $document) { if ($document instanceof Apache_Solr_Document) { $documentsXmlFragment .= $this->_documentToXmlFragmen...
Add an array of Solr Documents to the index all at once @param array $documents Should be an array of Apache_Solr_Document instances @param boolean $allowDups @param boolean $overwritePending @param boolean $overwriteCommitted @param integer $commitWithin The number of milliseconds that a document must be committed wi...
entailment
protected function _documentToXmlFragment(Apache_Solr_Document $document) { $xml = '<doc'; if ($document->getBoost() !== false) { $xml .= ' boost="' . $document->getBoost() . '"'; } $xml .= '>'; foreach ($document as $key => $value) { $fieldBoost = $document->getFieldBoost($key); $key = htmls...
Create an XML fragment from a {@link Apache_Solr_Document} instance appropriate for use inside a Solr add call @return string
entailment
public function commit($expungeDeletes = false, $waitFlush = true, $waitSearcher = true, $timeout = 3600, $softCommit = false) { $rawPost = $this->getCompatibilityLayer()->createCommitXml( $expungeDeletes, $waitFlush, $waitSearcher, $timeout, $softCommit ); return $this->_sendRawPost($this->_upda...
Send a commit command. Will be synchronous unless both wait parameters are set to false. @param boolean $expungeDeletes Defaults to false, merge segments with deletes away @param boolean $waitFlush Defaults to true, block until index changes are flushed to disk @param boolean $waitSearcher Defaults to true, block un...
entailment
public function softCommit($expungeDeletes = false, $waitFlush = true, $waitSearcher = true, $timeout = 3600) { return $this->commit($expungeDeletes, $waitFlush, $waitSearcher, $timeout, true); }
Send a soft commit command. Will be synchronous unless both wait parameters are set to false. @param boolean $expungeDeletes Defaults to false, merge segments with deletes away @param boolean $waitFlush Defaults to true, block until index changes are flushed to disk @param boolean $waitSearcher Defaults to true, bloc...
entailment
public function deleteById($id, $fromPending = true, $fromCommitted = true, $timeout = 3600) { $pendingValue = $fromPending ? 'true' : 'false'; $committedValue = $fromCommitted ? 'true' : 'false'; //escape special xml characters $id = htmlspecialchars($id, ENT_NOQUOTES, 'UTF-8'); $rawPost = '<delete fromPe...
Create a delete document based on document ID @param string $id Expected to be utf-8 encoded @param boolean $fromPending @param boolean $fromCommitted @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception) @return Apache_Solr_Response @t...
entailment
public function deleteByMultipleIds($ids, $fromPending = true, $fromCommitted = true, $timeout = 3600) { $pendingValue = $fromPending ? 'true' : 'false'; $committedValue = $fromCommitted ? 'true' : 'false'; $rawPost = '<delete fromPending="' . $pendingValue . '" fromCommitted="' . $committedValue . '">'; for...
Create and post a delete document based on multiple document IDs. @param array $ids Expected to be utf-8 encoded strings @param boolean $fromPending @param boolean $fromCommitted @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception) @ret...
entailment
public function deleteByQuery($rawQuery, $fromPending = true, $fromCommitted = true, $timeout = 3600) { $pendingValue = $fromPending ? 'true' : 'false'; $committedValue = $fromCommitted ? 'true' : 'false'; // escape special xml characters $rawQuery = htmlspecialchars($rawQuery, ENT_NOQUOTES, 'UTF-8'); $raw...
Create a delete document based on a query and submit it @param string $rawQuery Expected to be utf-8 encoded @param boolean $fromPending @param boolean $fromCommitted @param float $timeout Maximum expected duration of the delete operation on the server (otherwise, will throw a communication exception) @return Apache_S...
entailment