/** * Processes LDAP search results and constructs their model instances. * * @param resource $results * * @return array */ public function process($results) { // Normalize entries. Get entries returns false on failure. // We'll always want an array in this situation. $entries = $this->connection->getEntries($results) ?: []; if ($this->builder->isRaw()) { // If the builder is asking for a raw // LDAP result, we can return here. return $entries; } $models = []; if (Arr::has($entries, 'count')) { for ($i = 0; $i < $entries['count']; $i++) { // We'll go through each entry and construct a new // model instance with the raw LDAP attributes. $models[] = $this->newLdapEntry($entries[$i]); } } if (!$this->builder->isPaginated()) { // If the current query isn't paginated, // we'll sort the models array here. $models = $this->processSort($models); } return $models; }
/** * Try to get the token from the route parameters. * * @param \Illuminate\Http\Request $request * * @return null|string */ public function parse(Request $request) { // WARNING: Only use this parser if you know what you're doing! // It will only work with poorly-specified aspects of certain Lumen releases. $route = $request->route(); if (is_array($route) && Arr::has($route, '2.' . $this->key)) { // Route is the expected kind of array, and has a parameter with the key we want. return $route[2][$this->key]; } }
/** * Returns an array of translation keys specific to the currently requested controller/action. * * @param $namespace * @param $group * @param $item * @return mixed */ protected function _buildTranslationKeys($namespace, $group, $item) { if (!Arr::has($this->_translationKeys, "{$namespace}.{$group}.{$item}")) { $controller = "controller:{$this->_getController()}"; $action = "action:{$this->_getAction()}"; $key = "key:{$item}"; // The order of these matter. We always search from most specific to least specific. Arr::set($this->_translationKeys, "{$namespace}.{$group}.{$item}", ["{$controller}_{$action}_{$key}", "{$action}_{$key}", "{$controller}_{$key}", "{$item}"]); } return Arr::get($this->_translationKeys, "{$namespace}.{$group}.{$item}"); }
/** * Determine if a user exists in the repository. * * @param string $identification * @param string $type Must be one of properties defined in User class * @return bool */ public function has($identification, $type = 'uid') { if ($type == "uid") { return Arr::has($this->items, $identification); } else { return Arr::where((array) $this->items, function ($key, $value) use($identification, $type) { if (property_exists($value, $type)) { return false; } return $value->{$type} == $identification; }); } }
public static function all($params = []) { $metadata = []; $response = static::requestToArray('GET', null, $params); if (Arr::has($response, 'metadata')) { $metadata = Arr::pull($response, 'metadata'); $response = Arr::pull($response, 'data'); } // Create collection of current class $collection = Collection::makeOf(static::class, $response); // Set metada property to main object foreach ($metadata as $key => $value) { $collection->{$key} = $value; } return $collection; }
/** * Execute the console command. * * @return mixed * @codeCoverageIgnore */ public function handle() { $time = time(); DB::connection('econt')->disableQueryLog(); $this->comment(PHP_EOL . 'Starting...'); $this->comment(PHP_EOL . 'Importing zones and settlements... Please wait.'); Zone::whereRaw(1)->delete(); Settlement::whereRaw(1)->delete(); foreach (App::make('Econt')->zones() as $zone) { (new Zone())->import($zone); $zone_id = Arr::has($zone, 'id') ? Arr::get($zone, 'id') : 0; foreach (App::make('Econt')->settlements($zone_id) as $settlement) { if (!is_array($settlement)) { continue; } (new Settlement())->import($settlement); } } $this->comment(PHP_EOL . 'Zones and settlements imported successfully.'); $this->comment(PHP_EOL . 'Importing regions... Please wait.'); Region::whereRaw(1)->delete(); foreach (App::make('Econt')->regions() as $region) { (new Region())->import($region); } $this->comment(PHP_EOL . 'Regions imported successfully.' . PHP_EOL); $this->comment(PHP_EOL . 'Importing neighbourhoods... Please wait.'); Neighbourhood::whereRaw(1)->delete(); foreach (App::make('Econt')->neighbourhoods() as $region) { (new Neighbourhood())->import($region); } $this->comment(PHP_EOL . 'Neighbourhoods imported successfully.' . PHP_EOL); $this->comment(PHP_EOL . 'Importing streets... Please wait.'); Street::whereRaw(1)->delete(); foreach (App::make('Econt')->streets() as $region) { (new Street())->import($region); } $this->comment(PHP_EOL . 'Streets imported successfully.' . PHP_EOL); $this->comment(PHP_EOL . 'Importing offices... Please wait.'); Office::whereRaw(1)->delete(); foreach (App::make('Econt')->offices() as $region) { (new Office())->import($region); } $this->comment(PHP_EOL . 'Offices imported successfully.' . PHP_EOL); $this->comment(PHP_EOL . sprintf('Finished in %f minutes.', (time() - $time) / 60)); }
/** * Synchronize keys found in project files but missing in languages. * * @param $translationFiles * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException * @return void */ private function syncKeysFromFiles($translationFiles) { $this->info('Reading translation keys from files...'); // An array of all translation keys as found in project files. $allKeysInFiles = $this->manager->collectFromFiles(); foreach ($translationFiles as $fileName => $languages) { foreach ($languages as $languageKey => $path) { $fileContent = $this->manager->getFileContent($path); if (isset($allKeysInFiles[$fileName])) { $missingKeys = array_diff($allKeysInFiles[$fileName], array_keys(array_dot($fileContent))); foreach ($missingKeys as $i => $missingKey) { if (Arr::has($fileContent, $missingKey)) { unset($missingKeys[$i]); } } $this->fillMissingKeys($fileName, $missingKeys, $languageKey); } } } }
public function condition($inputs) { if (!Arr::has($inputs, $this->column)) { return null; } $this->value = Arr::get($inputs, $this->column); $value = array_filter($this->value, function ($val) { return $val !== ''; }); if (empty($value)) { return null; } if (!isset($value['start'])) { return $this->buildCondition($this->column, '<=', $value['end']); } if (!isset($value['end'])) { return $this->buildCondition($this->column, '>=', $value['start']); } $this->query = 'whereBetween'; return $this->buildCondition($this->column, $this->value); }
/** * Get the specified option value. * * @param string $key * @param mixed $default * @param bool $bool convert '0', '1' to bool value * @return mixed */ public function get($key, $default = null, $bool = true) { if (!$this->has($key) && Arr::has(config('options'), $key)) { $this->set($key, config("options.{$key}")); } $value = Arr::get($this->items, $key, $default); if (!$bool) { return $value; } switch (strtolower($value)) { case 'true': case '1': return true; case 'false': case '0': return false; case 'null': case '(null)': return; default: return $value; break; } }
/** * @param array $data * @param string|array $columns * @return array|mixed */ protected static function getDataByColumn($data, $columns) { if (is_string($columns)) { return Arr::get($data, $columns); } if (is_array($columns)) { $value = []; foreach ($columns as $name => $column) { if (!Arr::has($data, $column)) { continue; } $value[$name] = Arr::get($data, $column); } return $value; } }
/** * Returns true / false if the specified attribute * exists in the attributes array. * * @param int|string $key * @param int|string $subKey * * @return bool */ public function hasAttribute($key, $subKey = null) { if (is_null($subKey)) { return Arr::has($this->attributes, $key); } return Arr::has($this->attributes, "{$key}.{$subKey}"); }
/** * Save the expression * * @param string $key * @param mixed $expression * @return void */ protected function storeExpression($key, $expression) { if (A::has($this->expressions, $key)) { $this->expressions = A::set($this->expressions, $key, $expression); } else { $this->expressions = A::add($this->expressions, $key, $expression); } $this->reload(); }
/** * check if index already exists * * @param null $index * @return bool */ public function has($index = null) { return Arr::has($this->data, $index); }
/** * Check if a configuration setting exists * * @param string $key * @return boolean */ public function has($key) { return $this->arrHelper->has($this->data, $key); }
/** * Determine if an item exists at an offset. * * @param mixed $key * @return bool */ public function offsetExists($key) { return Arr::has($this->convert(), $key); }
/** * Checks if an attribute exists. * * @param string $attribute * @return bool */ public function hasAttribute($attribute) { return Arr::has($this->attributes(), $attribute); }
/** * Determine if the request contains a given input item key. * * @param string|array $key * @return bool */ public function exists($key) { $keys = is_array($key) ? $key : func_get_args(); $input = $this->all(); foreach ($keys as $value) { if (!Arr::has($input, $value)) { return false; } } return true; }
/** * Returns the manager required option. * * @return bool */ public function getManagerAttribute() { return Arr::has($this->options, 'manager') ? Arr::get($this->options, 'manager') == true : false; }
/** * @param InputInterface $input * @param OutputInterface $output * @param Package $package * @return string */ protected function askForVersion(InputInterface $input, OutputInterface $output, Package $package) { $helper = $this->getHelper('question'); $suggest = null; if ($package->latestTag && preg_match('/^(?<prefix>v)?(?<version>[0-9]+\\.[0-9]+\\.[0-9]+)$/', $package->latestTag, $m)) { list($major, $minor, $patch) = explode('.', $m['version']); $major = intval($major); $minor = intval($minor); $patch = intval($patch); $up = $input->getOption('up'); switch ($up) { case 'major': $major++; break; case 'minor': $minor++; break; case 'patch': $patch++; break; } $suggest = (Arr::has($m, 'prefix') ? Arr::get($m, 'prefix') : '') . join('.', [$major, $minor, $patch]); } $question = new Question('Specify the version to increment to or leave empty to skip: '); if ($suggest) { $question->setAutocompleterValues([$suggest]); } return $helper->ask($input, $output, $question); }
public static function createFromRequest(array $data) { $result = new static(); foreach ($result as $expected => $default) { $result->{$expected} = Arr::has($data, $expected) ? Arr::get($data, $expected) : null; } foreach (static::RequestMapping as $expected => $mapping) { $result->{$expected} = Arr::has($data, $mapping) ? Arr::get($data, $mapping) : null; } foreach (static::TypeMapping as $expected => $type) { $method = $type . 'val'; $result->{$expected} = $method($result->{$expected}); } if (!in_array($result->type, static::DocumentTypes)) { $result->type = static::Waybill; } $result->ids = new Collection([Arr::get($data, 'waybill')]); return $result; }
/** * Determine if the given session value exists. * * @param string $key * @return bool */ public function has($key) { return Arr::has($_SESSION, $key); }
/** * Check if the flash notification has an option. * * @param string $key * * @return bool */ public function hasOption($key) { return Arr::has($this->options(true), $key); }
/** * Check if setting key exists * * @param $key * @return mixed */ public function has($key) { $this->prepare(); return Arr::has($this->data, $key); }
/** * Determine if an item exists at an offset. * * @param mixed $key * * @return bool */ public function offsetExists($key) { return Arr::has($this->toArray(), $key); }
/** * Validate that an attribute is a string. * * @param string $attribute * @param mixed $value * @return bool */ protected function validateString($attribute, $value) { if (!Arr::has($this->data, $attribute)) { return true; } return is_null($value) || is_string($value); }
/** * Get field id * * @param string $name * @param array $options * * @return mixed|string */ protected function getFieldId($name, array $options = []) { if (Arr::has($options, 'field.id')) { return Arr::get($options, 'field.id'); } return 'field-' . str_replace('_', '-', $name); }
/** * Determine if the given configuration value exists. * * @param string $key * @return bool */ public function has($key) { return Arr::has($this->items, $key); }
/** * Check if setting key exists * * @param $key * @return mixed */ public function has($key) { return Arr::has($this->data, $key); }
/** * Check if an item exists in an array using "dot" notation. * * @param array $array * @param string $key * @return bool */ function array_has($array, $key) { return Arr::has($array, $key); }
public static function createFromRequest(array $data) { $result = new static(); foreach ($result as $expected => $default) { $result->{$expected} = Arr::has($data, $expected) ? Arr::get($data, $expected) : null; } foreach (static::RequestMapping as $expected => $mapping) { $result->{$expected} = Arr::has($data, $mapping) ? Arr::get($data, $mapping) : null; } switch ($result->payerType) { case 'sender': $result->payerType = 0; break; case 'receiver': $result->payerType = 1; break; case 'third-party': $result->payerType = 2; break; default: throw new SpeedyException('Invalid payer type detected.'); } foreach (static::TypeMapping as $expected => $type) { $method = $type . 'val'; $result->{$expected} = $method($result->{$expected}); } $result->mapSides(); $result->mapBeforePaymentOptions($data); $result->mapNullable(); if (!$result->serviceTypeId) { $result->serviceTypeId = CourierService::DefaultServiceId; } if (!$result->parcelsCount) { $result->parcelsCount = 1; } if (0 < $result->amountCodBase) { $result->includeShippingPriceInCod = true; } if (Arr::has($data, 'services.oc') && 0 < ($oc = (double) Arr::get($data, 'services.oc'))) { $result->amountInsuranceBase = $oc; $result->payerTypeInsurance = $result->payerType; } if (Arr::has($data, 'services.dp.documents')) { $result->backDocumentsRequest = !!Arr::get($data, 'services.dp.documents'); } if (Arr::has($data, 'services.dp.receipt')) { $result->backReceiptRequest = !!Arr::get($data, 'services.dp.receipt'); } foreach (static::Optional as $optional) { if (!$result->{$optional}) { unset($result->{$optional}); } } $result->mapParcels(); return $result; }