Exemplo n.º 1
1
 /**
  * Get an item from an array or object using "dot" notation.
  *
  * @param  mixed   $target
  * @param  string|array  $key
  * @param  mixed   $default
  * @return mixed
  */
 function data_get($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 Collection) {
                 $target = $target->all();
             } elseif (!is_array($target)) {
                 return value($default);
             }
             $result = Arr::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 value($default);
         }
     }
     return $target;
 }
Exemplo n.º 2
0
 public function testBulkOperationException()
 {
     $bulkItems = new Collection([['id' => 1], ['id' => 2], ['id' => 3], ['id' => 4]]);
     $items = [['create' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 1, 'status' => 409, 'error' => ['type' => 'document_already_exists_exception', 'reason' => '[my_index][1]: document already exists', 'shard' => '1', 'index' => 'my_index']]], ['update' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 2, 'status' => 404, 'error' => ['type' => 'document_missing_exception', 'reason' => '[my_index][2]: document missing', 'shard' => '-1', 'index' => 'my_index']]], ['delete' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 3, 'status' => 404, 'found' => false]], ['index' => ['_index' => 'my_index', '_type' => 'my_type', '_id' => 4, 'status' => 200]]];
     $e = BulkOperationException::createForResults($items, $bulkItems->all());
     $failedItems = $e->getFailedItems();
     $failedIds = Arr::pluck($failedItems, 'id');
     $this->assertEquals([1, 2], $failedIds);
 }
Exemplo n.º 3
0
 /**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     $ids = $this->argument('id');
     if (count($ids) === 1 && $ids[0] === 'all') {
         $ids = Arr::pluck($this->laravel['queue.failer']->all(), 'id');
     }
     foreach ($ids as $id) {
         $this->retryJob($id);
     }
 }
Exemplo n.º 4
0
 /**
  * Get the values of a given key.
  *
  * @param  string  $value
  * @param  string|null  $key
  * @return static
  */
 public function pluck($value, $key = null)
 {
     return new static(Arr::pluck($this->items, $value, $key));
 }
Exemplo n.º 5
0
 /**
  * Get an array with the values of a given column.
  *
  * @param  string  $column
  * @param  string|null  $key
  * @return array
  */
 public function pluck($column, $key = null)
 {
     $results = $this->get(is_null($key) ? [$column] : [$column, $key]);
     // If the columns are qualified with a table or have an alias, we cannot use
     // those directly in the "pluck" operations since the results from the DB
     // are only keyed by the column itself. We'll strip the table out here.
     return Arr::pluck($results, $this->stripTableForPluck($column), $this->stripTableForPluck($key));
 }
Exemplo n.º 6
0
 /**
  * Pluck an array of values from an array.
  *
  * @param  array   $array
  * @param  string  $value
  * @param  string  $key
  * @return array
  */
 function array_pluck($array, $value, $key = null)
 {
     return Arr::pluck($array, $value, $key);
 }
Exemplo n.º 7
0
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Response;
use Zend\Feed\Exception\InvalidArgumentException;
use Zend\Feed\Writer\Entry;
use Zend\Feed\Writer\Feed;
Route::get('/feeds/{path}', function ($path) {
    /** @type FeedModel $model */
    $model = FeedModel::where('path', '=', $path)->first();
    if ($model === null) {
        return Response::make('Not Found', 404);
    }
    $feed = new Feed();
    $feed->setTitle($model->getAttribute('title'))->setDescription($model->getAttribute('description'))->setBaseUrl(Url::to('/'))->setGenerator('OctoberCMS/Adrenth.RssFetcher')->setId('Adrenth.RssFecther.' . $model->getAttribute('id'))->setLink(Url::to('/feeds/' . $path))->setFeedLink(Url::to('/feeds/' . $path), $model->getAttribute('type'))->setDateModified()->addAuthor(['name' => 'OctoberCMS']);
    /** @type Collection $sources */
    $sources = $model->sources;
    $ids = Arr::pluck($sources->toArray(), 'id');
    $items = [];
    Source::with(['items' => function ($builder) use(&$items, $model) {
        $items = $builder->where('is_published', '=', 1)->whereDate('pub_date', '=', date('Y-m-d'))->orderBy('pub_date', 'desc')->limit($model->getAttribute('max_items'))->get();
    }])->whereIn('id', $ids)->where('is_enabled', '=', 1)->get();
    /** @type Item $item */
    foreach ($items as $item) {
        try {
            $entry = new Entry();
            $entry->setId((string) $item->getAttribute('id'))->setTitle($item->getAttribute('title'))->setDescription($item->getAttribute('description'))->setLink($item->getAttribute('link'))->setDateModified($item->getAttribute('pub_date'));
            $comments = $item->getAttribute('comments');
            if (!empty($comments)) {
                $entry->setCommentLink($comments);
            }
            $category = $item->getAttribute('category');
            if (!empty($category)) {
Exemplo n.º 8
0
 /**
  * Determine whether given table has been already joined.
  *
  * @param  \Sofa\Eloquence\Builder $query
  * @param  string  $table
  * @return boolean
  */
 protected function alreadyJoined(Builder $query, $table)
 {
     $joined = Arr::pluck((array) $query->getQuery()->joins, 'table');
     return in_array($table, $joined);
 }
Exemplo n.º 9
0
 /**
  * Prepare chart data.
  *
  * @param  \Arcanedev\LogViewer\Tables\StatsTable  $stats
  *
  * @return string
  */
 protected function prepareChartData(StatsTable $stats)
 {
     $totals = $stats->totals()->all();
     return json_encode(['labels' => Arr::pluck($totals, 'label'), 'datasets' => [['data' => Arr::pluck($totals, 'value'), 'backgroundColor' => Arr::pluck($totals, 'color'), 'hoverBackgroundColor' => Arr::pluck($totals, 'highlight')]]]);
 }
Exemplo n.º 10
0
 /**
  * Get an array with the values of a given column.
  *
  * @param  string  $column
  * @param  string|null  $key
  * @return array
  */
 public function pluck($column, $key = null)
 {
     $results = $this->get(is_null($key) ? [$column] : [$column, $key]);
     // Convert ObjectID's to strings
     if ($key == '_id') {
         $results = $results->map(function ($item) {
             $item['_id'] = (string) $item['_id'];
             return $item;
         });
     }
     $p = Arr::pluck($results, $column, $key);
     return $this->useCollections ? new Collection($p) : $p;
 }