/**
  * Replace all of the named parameters in the path.
  *
  * @param  string $path
  * @param  array  $parameters
  *
  * @return string
  */
 protected function replaceNamedParameters($path, &$parameters)
 {
     $this->ensureTenancyInParameters($path, $parameters);
     return preg_replace_callback('/\\{(.*?)\\??\\}/', function ($m) use(&$parameters) {
         return isset($parameters[$m[1]]) ? Arr::pull($parameters, $m[1]) : $m[0];
     }, $path);
 }
Ejemplo n.º 2
0
 /**
  * 根据配置文件初始化client
  * @param  array  $servers
  * @param int  $timeOut
  * @return  void
  */
 public function __construct(array $servers = [], $timeOut = 5)
 {
     $cluster = Arr::pull($servers, 'cluster');
     $options = (array) Arr::pull($servers, 'options');
     $this->timeOut = Arr::pull($servers, 'timeout');
     $this->clients = $this->createClients($servers, $options);
 }
Ejemplo n.º 3
0
 /**
  * Create multiple clusters (aggregate clients).
  *
  * @param  array  $clusters
  * @param  array  $options
  * @return void
  */
 protected function createClusters(array $clusters, array $options = [])
 {
     $options = array_merge($options, (array) Arr::pull($clusters, 'options'));
     foreach ($clusters as $name => $servers) {
         $this->clients += $this->createAggregateClient($name, $servers, array_merge($options, (array) Arr::pull($servers, 'options')));
     }
 }
Ejemplo n.º 4
0
 /**
  * 根据配置文件初始化client
  *
  * @param  array  $servers
  * @return void
  */
 public function __construct(array $servers = [], $timeOut = 5)
 {
     $cluster = Arr::pull($servers, 'cluster');
     $options = (array) Arr::pull($servers, 'options');
     $this->clients = $this->createClients($servers, $options);
     $this->timeOut = $timeOut;
     $this->curConnection = $this->clients['default'];
 }
Ejemplo n.º 5
0
 /**
  * Broadcast the given event.
  *
  * @param  array  $channels
  * @param  string  $event
  * @param  array  $payload
  * @return void
  */
 public function broadcast(array $channels, $event, array $payload = [])
 {
     $socket = Arr::pull($payload, 'socket');
     $payload = ['event' => $event, 'data' => $payload, 'socket' => $socket];
     foreach ($this->formatChannels($channels) as $channel) {
         LaravooleFacade::task(['channel' => $channel, 'payload' => $payload]);
     }
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function getAccessTokenResponse($code)
 {
     $postKey = version_compare(ClientInterface::VERSION, '6') === 1 ? 'form_params' : 'body';
     $response = $this->getHttpClient()->post($this->getTokenUrl(), [$postKey => $this->getTokenFields($code)]);
     $data = [];
     parse_str($response->getBody(), $data);
     return Arr::add($data, 'expires_in', Arr::pull($data, 'expires'));
 }
Ejemplo n.º 7
0
 /**
  * Broadcast the given event.
  *
  * @param  array  $channels
  * @param  string  $event
  * @param  array  $payload
  * @return void
  */
 public function broadcast(array $channels, $event, array $payload = [])
 {
     $socket = Arr::pull($payload, 'socket');
     $response = $this->pusher->trigger($this->formatChannels($channels), $event, $payload, $socket);
     if (is_array($response) && $response['status'] >= 200 && $response['status'] <= 299 || $response === true) {
         return;
     }
     throw new BroadcastException(is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']);
 }
Ejemplo n.º 8
0
 /**
  * Create a new driver instance.
  *
  * @param  string  $driver
  *
  * @return \Orchestra\Tenanti\Migrator\FactoryInterface
  *
  * @throws \InvalidArgumentException
  */
 protected function createDriver($driver)
 {
     $config = Arr::pull($this->config, "drivers.{$driver}");
     $chunk = Arr::pull($this->config, 'chunk', 100);
     if (is_null($config)) {
         throw new InvalidArgumentException("Driver [{$driver}] not supported.");
     }
     return $this->app->make($this->resolver, [$this->app, $driver, $config, $chunk]);
 }
Ejemplo n.º 9
0
 /**
  * Broadcast the given event.
  *
  * @param  array  $channels
  * @param  string  $event
  * @param  array  $payload
  * @return void
  */
 public function broadcast(array $channels, $event, array $payload = [])
 {
     $connection = $this->redis->connection($this->connection);
     $socket = Arr::pull($payload, 'socket');
     $payload = json_encode(['event' => $event, 'data' => $payload, 'socket' => $socket]);
     foreach ($this->formatChannels($channels) as $channel) {
         $connection->publish($channel, $payload);
     }
 }
Ejemplo n.º 10
0
 /**
  * Create a new Redis connection instance.
  *
  * @param  array  $servers
  * @return void
  */
 public function __construct(array $servers = [])
 {
     $cluster = Arr::pull($servers, 'cluster');
     $options = array_merge(['timeout' => 10.0], (array) Arr::pull($servers, 'options'));
     if ($cluster) {
         $this->clients = $this->createAggregateClient($servers, $options);
     } else {
         $this->clients = $this->createSingleClients($servers, $options);
     }
 }
Ejemplo n.º 11
0
 /**
  * Create a new Redis connection instance.
  *
  * @param  array  $servers
  * @return void
  */
 public function __construct(array $servers = [])
 {
     $cluster = Arr::pull($servers, 'cluster');
     if ($cluster) {
         $options = (array) Arr::pull($servers['clusterConfig'], 'options');
         $this->clients = $this->createAggregateClient($servers['clusterConfig'], $options);
     } else {
         $options = (array) Arr::pull($servers, 'options');
         $this->clients = $this->createSingleClients($servers, $options);
     }
 }
 /**
  * Register the service provider.
  *
  * @return void
  */
 public function register()
 {
     $this->app->singleton('redis', function ($app) {
         $servers = $app['config']['database.redis'];
         $client = Arr::pull($servers, 'client', 'predis');
         if ($client === 'phpredis') {
             return new PhpRedisDatabase($servers);
         } else {
             return new PredisDatabase($servers);
         }
     });
 }
Ejemplo n.º 13
0
 /**
  * Create an array of single connection or sentinel clients
  *
  * @param  array  $servers
  * @param  array  $options
  * @return array
  */
 protected function createSingleClients(array $servers, array $options = [])
 {
     $clients = [];
     foreach ($servers as $key => $server) {
         $options = array_merge($options, Arr::pull($server, 'options'));
         $clients[$key] = new Client($server, $options);
         if (isset($options['update_sentinels']) && boolval($options['update_sentinels']) === true) {
             $clients[$key]->getConnection()->setUpdateSentinels(true);
         }
     }
     return $clients;
 }
Ejemplo n.º 14
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.º 15
0
 /**
  * Get the hydrated models without eager loading.
  *
  * @param array $columns
  *
  * @return \Illuminate\Database\Eloquent\Model[]
  */
 public function getModels($columns = ['*'])
 {
     $results = $this->query->get($columns);
     $connection = $this->model->getConnectionName();
     // Check for joined relations
     if (!empty($this->joined)) {
         foreach ($results as $key => $result) {
             $relation_values = [];
             foreach ($result as $column => $value) {
                 Arr::set($relation_values, $column, $value);
             }
             foreach ($this->joined as $relationName) {
                 $relation = $this->getRelation($relationName);
                 $relation_values[$relationName] = $relation->getRelated()->newFromBuilder(Arr::pull($relation_values, $relationName), $connection);
             }
             $results[$key] = $relation_values;
         }
     }
     return $this->model->hydrate($results, $connection)->all();
 }
 /**
  * Perform post-registration booting of services.
  *
  * @param  ResponseFactory  $factory
  * @return void
  */
 public function boot()
 {
     Response::macro('png', function ($src = "", $status = 200, $header = []) {
         $last_modified = Arr::pull($header, 'Last-Modified', time());
         $etag = md5($src);
         // Checking if the client is validating his cache and if it is current.
         if (strtotime(Arr::get($_SERVER, 'If-Modified-Since')) == $last_modified || trim(Arr::get($_SERVER, 'HTTP_IF_NONE_MATCH')) == $etag) {
             // Client's cache IS current, so we just respond '304 Not Modified'.
             $status = 304;
             $src = "";
         }
         return Response::stream(function () use($src, $status) {
             echo $src;
         }, $status, array_merge(['Content-type' => 'image/png', 'Last-Modified' => gmdate('D, d M Y H:i:s', $last_modified) . ' GMT', 'Cache-Control' => 'public, max-age=' . option('cache_expire_time'), 'Expires' => gmdate('D, d M Y H:i:s', $last_modified + option('cache_expire_time')) . ' GMT', 'Etag' => $etag], $header));
     });
     Response::macro('rawJson', function ($src = "", $status = 200, $header = []) {
         $last_modified = Arr::get($header, 'Last-Modified', time());
         if (strtotime(Arr::get($_SERVER, 'If-Modified-Since')) >= $last_modified) {
             $status = 304;
             $src = "";
         }
         return Response::make($src, $status, array_merge(['Content-type' => 'application/json', 'Cache-Control' => 'public, max-age=' . option('cache_expire_time')], $header));
     });
 }
Ejemplo n.º 17
0
 private function filterApply($resources, $filters)
 {
     $limit = (int) Arr::pull($filters, 'limit');
     if ($limit > 0) {
         $resources = $resources->slice(0, $limit);
     }
     foreach ($filters as $key => $value) {
         $resources = $this->filter($resources, $key, $value);
     }
     return $resources->values();
 }
Ejemplo n.º 18
0
 /**
  * Get the rate limit expiration time for this route.
  *
  * @return int
  */
 public function getRateExpiration()
 {
     if (is_null($this->rateExpiration)) {
         $this->rateExpiration = Arr::pull($this->action, 'expires', 0);
         $this->findControllerOptions('rateLimit', function ($value) {
             $this->rateExpiration = $value['expires'];
         });
     }
     return $this->rateExpiration;
 }
Ejemplo n.º 19
0
 /**
  * {@inheritdoc}
  */
 public function remove($name)
 {
     return Arr::pull($this->attributes, $name);
 }
Ejemplo n.º 20
0
 /**
  * Prepare configuration values.
  *
  * @param  string  $driver
  *
  * @return array|null
  */
 protected function setupDriverConfig($driver)
 {
     if (isset($this->config[$driver])) {
         return;
     }
     if (is_null($config = Arr::pull($this->config, "drivers.{$driver}"))) {
         return;
     }
     $connection = Arr::get($this->config, 'connection');
     if (!is_null($connection) && $this->driverExcludedByOptions($driver, $connection['options'])) {
         $connection = null;
     }
     return $this->config[$driver] = array_merge($config, ['connection' => $connection]);
 }
Ejemplo n.º 21
0
 /**
  * Set the grid paginate.
  *
  * @return void
  */
 protected function setPaginate()
 {
     $paginate = Arr::pull($this->queries, 'paginate');
     $this->queries['paginate'] = empty($paginate) ? [20] : $paginate;
 }
Ejemplo n.º 22
0
 /**
  * Replace all of the named parameters in the path.
  *
  * @param  string  $path
  * @param  array  $parameters
  * @return string
  */
 protected function replaceNamedParameters($path, &$parameters)
 {
     return preg_replace_callback('/\\{(.*?)\\??\\}/', function ($m) use(&$parameters) {
         if (isset($parameters[$m[1]])) {
             return Arr::pull($parameters, $m[1]);
         } elseif (isset($this->defaultParameters[$m[1]])) {
             return $this->defaultParameters[$m[1]];
         } else {
             return $m[0];
         }
     }, $path);
 }
Ejemplo n.º 23
0
 /**
  * Create a new Redis connection instance.
  *
  * @param  array  $servers
  * @return void
  */
 public function __construct(array $server = [])
 {
     $options = (array) Arr::pull($servers, 'options');
     $this->clients = $this->createSingleClients($server, $options);
 }
Ejemplo n.º 24
0
 /**
  * Store the uploaded file on a filesystem disk.
  *
  * @param  string  $path
  * @param  string  $name
  * @param  array  $options
  * @return string|false
  */
 public function storeAs($path, $name, $options = [])
 {
     $factory = Container::getInstance()->make(FilesystemFactory::class);
     $disk = Arr::pull($options, 'disk');
     return $factory->disk($disk)->putFileAs($path, $this, $name, $options);
 }
Ejemplo n.º 25
0
 /**
  * Normalize url parameters.
  *
  * @param mixed $parameters
  * @return array
  */
 protected function normalizeParameters($parameters)
 {
     if (is_string($parameters)) {
         $parameters = ['path' => $parameters];
     } elseif (!is_array($parameters)) {
         $parameters = [$parameters];
     }
     $normalized = [];
     foreach ($parameters as $key => $value) {
         if (is_int($key) && $value instanceof UrlResource) {
             $normalized = array_merge($normalized, $value->forUrl());
         } elseif ($value instanceof Type) {
             $normalized[$key] = $value->name;
         } else {
             if ($value instanceof Entity) {
                 $normalized["{$key}_type"] = $value->type->name;
             }
             $normalized[$key] = $value;
         }
     }
     if (isset($normalized['host']) && strpos($normalized['host'], '//') !== false) {
         $context = Arr::pull($normalized, 'host');
         $normalized += $this->parseContext($context);
     }
     return $normalized + ['path' => '', '?' => [], '#' => null];
 }
Ejemplo n.º 26
0
 /**
  * Get a value from the array, and remove it.
  *
  * @param  array $array
  * @param  string $key
  * @param  mixed $default
  * @return mixed
  */
 function array_pull(&$array, $key, $default = null)
 {
     return Arr::pull($array, $key, $default);
 }
Ejemplo n.º 27
0
 /**
  * Builds a FontAwesome icon HTML.
  *
  * @param string $name    The icon name, as indicated in the FA documentation.
  * @param array  $options Extra class/es to add to the icon
  *
  * @return string
  */
 public function icon($name, $options = [])
 {
     $options = $this->parseOptions($options);
     $options['class'] = $this->getClasses($name, Arr::pull($options, 'class'));
     return new HtmlString($this->openTag($this->attributes($options)) . $this->closeTag());
 }
Ejemplo n.º 28
0
 /**
  * Setup the route properties.
  *
  * @return void
  */
 protected function setupRouteProperties(Request $request, $route)
 {
     list($this->uri, $this->methods, $this->action) = $this->adapter->getRouteProperties($route, $request);
     $this->versions = Arr::pull($this->action, 'version');
     $this->conditionalRequest = Arr::pull($this->action, 'conditionalRequest', true);
     $this->middleware = Arr::pull($this->action, 'middleware', []);
     $this->throttle = Arr::pull($this->action, 'throttle');
     $this->scopes = Arr::pull($this->action, 'scopes', []);
     $this->authenticationProviders = Arr::pull($this->action, 'providers', []);
     $this->rateLimit = Arr::pull($this->action, 'limit', 0);
     $this->rateExpiration = Arr::pull($this->action, 'expires', 0);
     // Now that the default route properties have been set we'll go ahead and merge
     // any controller properties to fully configure the route.
     $this->mergeControllerProperties();
     // If we have a string based throttle then we'll new up an instance of the
     // throttle through the container.
     if (is_string($this->throttle)) {
         $this->throttle = $this->container->make($this->throttle);
     }
 }
Ejemplo n.º 29
0
 /**
  * Get and remove an item from the collection.
  *
  * @param  mixed  $key
  * @param  mixed  $default
  * @return mixed
  */
 public function pull($key, $default = null)
 {
     return Arr::pull($this->items, $key, $default);
 }
Ejemplo n.º 30
-1
 /**
  * Broadcast the given event.
  *
  * @param  array  $channels
  * @param  string  $event
  * @param  array  $payload
  * @return void
  */
 public function broadcast(array $channels, $event, array $payload = [])
 {
     $socket = Arr::pull($payload, 'socket');
     $this->pusher->trigger($this->formatChannels($channels), $event, $payload, $socket);
 }