Esempio n. 1
0
 /**
  * {@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']);
 }
Esempio n. 2
0
 /**
  * {@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;
 }
Esempio n. 4
0
 /**
  * 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;
 }
Esempio n. 5
0
 /**
  * {@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']));
 }
Esempio n. 6
0
 /**
  * {@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']);
 }
Esempio n. 7
0
 /**
  * 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']);
 }
Esempio n. 8
0
 /**
  * {@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']);
 }
Esempio n. 9
0
 /**
  * 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']);
 }
Esempio n. 10
0
 /**
  * {@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;
 }
Esempio n. 11
0
 /**
  * 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);
     });
 }
Esempio n. 12
0
 /**
  * {@inheritdoc}
  */
 public function remove(string $name)
 {
     $value = $this->get($name);
     Arr::forget($this->values, $name);
     return $value;
 }
Esempio n. 13
0
 /**
  * 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.');
 }
Esempio n. 14
0
 /**
  * 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');
     });
 }
Esempio n. 16
0
 /**
  * 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;
 }
Esempio n. 17
0
 /**
  * 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));
 }
Esempio n. 18
0
 /**
  * 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;
 }
Esempio n. 19
0
 /**
  * {@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']);
 }
Esempio n. 20
0
 /**
  * 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);
 }
Esempio n. 21
0
 /**
  * {@inheritdoc}
  */
 public function getJobId() : string
 {
     return Arr::get($this->decoded, 'id');
 }
Esempio n. 22
0
 /**
  * Remove nested array value based on a separated key.
  *
  * @param string $key
  */
 public function offsetUnset($key)
 {
     Arr::forget($this->data, $key);
 }
Esempio n. 23
0
 /**
  * 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));
 }
Esempio n. 24
0
 /**
  * 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;
 }