Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * 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;
         });
     }
 }
Ejemplo n.º 5
0
 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;
 }
Ejemplo n.º 6
0
 /**
  * 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));
 }
Ejemplo n.º 7
0
 /**
  * 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);
             }
         }
     }
 }
Ejemplo n.º 8
0
 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;
     }
 }
Ejemplo n.º 10
0
 /**
  * @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;
     }
 }
Ejemplo n.º 11
0
 /**
  * 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}");
 }
Ejemplo n.º 12
0
 /**
  * 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();
 }
Ejemplo n.º 13
0
 /**
  * check if index already exists
  *
  * @param null $index
  * @return bool
  */
 public function has($index = null)
 {
     return Arr::has($this->data, $index);
 }
Ejemplo n.º 14
0
 /**
  * Check if a configuration setting exists
  *
  * @param  string $key
  * @return boolean
  */
 public function has($key)
 {
     return $this->arrHelper->has($this->data, $key);
 }
Ejemplo n.º 15
0
 /**
  * Determine if an item exists at an offset.
  *
  * @param  mixed  $key
  * @return bool
  */
 public function offsetExists($key)
 {
     return Arr::has($this->convert(), $key);
 }
Ejemplo n.º 16
0
 /**
  * Checks if an attribute exists.
  *
  * @param  string  $attribute
  * @return bool
  */
 public function hasAttribute($attribute)
 {
     return Arr::has($this->attributes(), $attribute);
 }
Ejemplo n.º 17
0
 /**
  * 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;
 }
Ejemplo n.º 18
0
 /**
  * Returns the manager required option.
  *
  * @return bool
  */
 public function getManagerAttribute()
 {
     return Arr::has($this->options, 'manager') ? Arr::get($this->options, 'manager') == true : false;
 }
Ejemplo n.º 19
0
 /**
  * @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);
 }
Ejemplo n.º 20
0
 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;
 }
Ejemplo n.º 21
0
 /**
  * Determine if the given session value exists.
  *
  * @param  string  $key
  * @return bool
  */
 public function has($key)
 {
     return Arr::has($_SESSION, $key);
 }
Ejemplo n.º 22
0
 /**
  * Check if the flash notification has an option.
  *
  * @param  string  $key
  *
  * @return bool
  */
 public function hasOption($key)
 {
     return Arr::has($this->options(true), $key);
 }
Ejemplo n.º 23
0
 /**
  * Check if setting key exists
  *
  * @param $key
  * @return mixed
  */
 public function has($key)
 {
     $this->prepare();
     return Arr::has($this->data, $key);
 }
Ejemplo n.º 24
0
 /**
  * Determine if an item exists at an offset.
  *
  * @param  mixed  $key
  *
  * @return bool
  */
 public function offsetExists($key)
 {
     return Arr::has($this->toArray(), $key);
 }
Ejemplo n.º 25
0
 /**
  * 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);
 }
Ejemplo n.º 26
0
 /**
  * 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);
 }
Ejemplo n.º 27
0
 /**
  * Determine if the given configuration value exists.
  *
  * @param  string  $key
  * @return bool
  */
 public function has($key)
 {
     return Arr::has($this->items, $key);
 }
Ejemplo n.º 28
0
 /**
  * Check if setting key exists
  *
  * @param $key
  * @return mixed
  */
 public function has($key)
 {
     return Arr::has($this->data, $key);
 }
Ejemplo n.º 29
0
 /**
  * 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);
 }
Ejemplo n.º 30
0
 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;
 }