/** * {@inheritdoc} */ protected function getConfig(array $config) : array { if (!array_key_exists('database', $config)) { throw new InvalidArgumentException('The gridfs connector requires database configuration.'); } return Arr::only($config, ['database']); }
/** * {@inheritdoc} */ protected function getConfig(array $config) : array { if (!array_key_exists('prefix', $config)) { $config['prefix'] = null; } return Arr::only($config, ['prefix']); }
/** * Get the cache configuration. * * @param string $name * * @throws \InvalidArgumentException * * @return array */ protected function getCacheConfig(string $name) : array { $cache = $this->config->get($this->getConfigName() . '.cached'); if (!is_array($config = Arr::get($cache, $name)) && !$config) { throw new InvalidArgumentException(sprintf('Cache [%s] not configured.', $name)); } $config['name'] = $name; return $config; }
/** * Sanitize a dataset using rules. * * @param array $rules * @param array $data * * @return array */ public function sanitize(array $rules, array $data) : array { list($data, $rules) = $this->runGlobalSanitizers($rules, $data); $availableRules = Arr::only($rules, array_keys($data)); foreach ($availableRules as $field => $ruleset) { $data[$field] = $this->sanitizeField($data, $field, $ruleset); } return $data; }
/** * {@inheritdoc} */ protected function getClient(array $config) { if (!array_key_exists('baseUri', $config)) { throw new InvalidArgumentException('The WebDav connector requires baseUri configuration.'); } if (!array_key_exists('prefix', $config)) { $config['prefix'] = null; } return new Client(Arr::only($config, ['prefix', 'baseUri'])); }
/** * {@inheritdoc} */ protected function getConfig(array $config) : array { if (!array_key_exists('prefix', $config)) { $config['prefix'] = null; } if (!array_key_exists('bucket', $config)) { throw new InvalidArgumentException('The awss3 connector requires a bucket configuration.'); } if (!array_key_exists('options', $config)) { $config['options'] = []; } return Arr::only($config, ['bucket', 'prefix', 'options']); }
/** * Get the configuration. * * @param string[] $config * * @throws \InvalidArgumentException * * @return string[] */ protected function getConfig(array $config) : array { if (!array_key_exists('path', $config)) { throw new InvalidArgumentException('The zip connector requires path configuration.'); } if (!array_key_exists('archive', $config)) { $config['archive'] = new ZipArchive(); } if (!array_key_exists('prefix', $config)) { $config['prefix'] = null; } return Arr::only($config, ['path', 'archive', 'prefix']); }
/** * {@inheritdoc} */ protected function getConfig(array $config) { if (!array_key_exists('host', $config)) { throw new InvalidArgumentException('The sftp connector requires host configuration.'); } if (!array_key_exists('port', $config)) { throw new InvalidArgumentException('The sftp connector requires port configuration.'); } if (!array_key_exists('username', $config)) { throw new InvalidArgumentException('The sftp connector requires username configuration.'); } if (!array_key_exists('password', $config)) { throw new InvalidArgumentException('The sftp connector requires password configuration.'); } return Arr::only($config, ['host', 'port', 'username', 'password']); }
/** * Get the configuration. * * @param array $config * * @throws \InvalidArgumentException * * @return string[] */ protected function getConfig(array $config) : array { if (!array_key_exists('path', $config)) { throw new InvalidArgumentException('The local connector requires path configuration.'); } if (!array_key_exists('write_flags', $config)) { $config['write_flags'] = LOCK_EX; } if (!array_key_exists('link_handling', $config)) { $config['link_handling'] = Local::DISALLOW_LINKS; } if (!array_key_exists('permissions', $config)) { $config['permissions'] = []; } return Arr::only($config, ['path', 'write_flags', 'link_handling', 'permissions']); }
/** * {@inheritdoc} */ public function resolveName() : string { $name = $this->getName(); $payload = json_decode($this->getRawBody(), true); if ($name === sprintf('%s@call', CallQueuedHandler::class)) { return Arr::get($payload, 'data.commandName', $name); } return $name; }
/** * Get the extension used by the view file. * * @param string $path * * @return string|null */ protected function getExtension(string $path) { $extensions = array_keys($this->extensions); return Arr::first($extensions, function ($key, $value) use($path) { return Str::endsWith($path, $value); }); }
/** * {@inheritdoc} */ public function remove(string $name) { $value = $this->get($name); Arr::forget($this->values, $name); return $value; }
/** * Parse the given view name or array. * * @param string|array $view * * @throws \InvalidArgumentException * * @return array */ protected function parseView($view) { if (is_string($view)) { return [$view, null, null]; } // If the given view is an array with numeric keys, we will just assume that // both a "pretty" and "plain" view were provided, so we will return this // array as is, since must should contain both views with numeric keys. if (is_array($view) && isset($view[0])) { return [$view[0], $view[1], null]; // If the view is an array, but doesn't contain numeric keys, we will assume // the the views are being explicitly specified and will extract them via // named keys instead, allowing the developers to use one or the other. } elseif (is_array($view)) { return [Arr::get($view, 'html'), Arr::get($view, 'text'), Arr::get($view, 'raw')]; } throw new InvalidArgumentException('Invalid view.'); }
/** * Filter directory contents by type. * * @param array $contents * @param string $type * * @return array */ private function filterContentsByType(array $contents, string $type) : array { $return = []; foreach ($contents as $key => $value) { if (Arr::get($contents, $key) === $value) { if (isset($value['path'])) { $return[$key] = $value['path']; } } } return array_values($return); }
/** * Get the environment argument from the console. * * @param array $args * * @return string|null */ protected function getEnvironmentArgument(array $args) { return Arr::first($args, function ($k, $v) { return Str::startsWith($v, '--env'); }); }
/** * Create Redis connection. * * @return \Viserio\Queue\Connectors\RedisQueue */ protected function createRedisConnection(array $config) : RedisQueue { $connect = new ConnectManager($this->config); $queue = new RedisQueue($connect->connection($config['connection']), $config['queue'], Arr::get($config, 'expire', 90)); return $queue; }
/** * Set additional meta on a payload string. * * @param string $payload * @param string $key * @param string|int $value * * @return string */ protected function setMeta(string $payload, string $key, $value) : string { $payload = json_decode($payload, true); return json_encode(Arr::set($payload, $key, (string) $value)); }
/** * Get an item from an array or object using "dot" notation. * * @param mixed $target * @param string|array $key * @param mixed $default * * @return mixed */ protected static function dataGet($target, $key, $default = null) { if (is_null($key)) { return $target; } $key = is_array($key) ? $key : explode('.', $key); while (($segment = array_shift($key)) !== null) { if ($segment === '*') { if ($target instanceof self) { $target = $target->all(); } elseif (!is_array($target)) { return Arr::value($default); } $result = $this->pluck($target, $key); return in_array('*', $key) ? Arr::collapse($result) : $result; } if (Arr::accessible($target) && Arr::exists($target, $segment)) { $target = $target[$segment]; } elseif (is_object($target) && isset($target->{$segment})) { $target = $target->{$segment}; } else { return Arr::value($default); } } return $target; }
/** * {@inheritdoc} */ protected function getClient(array $auth) { $client = new Rackspace($auth['endpoint'], ['username' => $auth['username'], 'apiKey' => $auth['apiKey']]); $urlType = Arr::get($auth, 'internal', false) ? 'internalURL' : 'publicURL'; return $client->objectStoreService('cloudFiles', $auth['region'], $urlType)->getContainer($auth['container']); }
/** * Get a queued cookie instance. * * @param string $key * @param mixed|null $default * * @return CookieContract|null */ public function queued(string $key, $default = null) { return Arr::get($this->queued, $key, $default); }
/** * {@inheritdoc} */ public function getJobId() : string { return Arr::get($this->decoded, 'id'); }
/** * Remove nested array value based on a separated key. * * @param string $key */ public function offsetUnset($key) { Arr::forget($this->data, $key); }
/** * Get a fresh Guzzle HTTP client instance. * * @param array $config * * @return \GuzzleHttp\Client */ protected function getHttpClient(array $config) : HttpClient { $guzzleConfig = Arr::get($config, 'guzzle', []); return new HttpClient(Arr::add($guzzleConfig, 'connect_timeout', 90)); }
/** * Parse the route action into a standard array. * * @param callable|array|null $action * * @throws \UnexpectedValueException * * @return array */ protected function parseAction($action) : array { // If no action is passed in right away, we assume the user will make use of // fluent routing. In that case, we set a default closure, to be executed // if the user never explicitly sets an action to handle the given uri. if (is_null($action)) { return ['uses' => function () { throw new LogicException(sprintf('Route for [%s] has no action.', $this->uri)); }]; } // If the action is already a Closure instance, we will just set that instance // as the "uses" property. if (is_callable($action)) { return ['uses' => $action]; } // If no "uses" property has been set, we will dig through the array to find a // Closure instance within this list. We will set the first Closure we come across. if (!isset($action['uses'])) { $action['uses'] = Arr::first($action, function ($key, $value) { return is_callable($value) && is_numeric($key); }); } if (is_string($action['uses']) && strpos($action['uses'], '::') === false) { if (!method_exists($action, '__invoke')) { throw new UnexpectedValueException(sprintf('Invalid route action: [%s]', $action['uses'])); } $action['uses'] = $action . '::__invoke'; } return $action; }