toArray() public method

Get the collection of items as a plain array.
public toArray ( ) : array
return array
Example #1
4
 public function send(Collection $data)
 {
     $validator = $this->validator($data->toArray(), $this->type);
     if (!$validator->fails()) {
         Mailer::send("emails.{$this->type}", $data->toArray(), function ($message) use($data) {
             $fromAddress = $data->get('from_address');
             $fromName = $data->get('from_name');
             $toAddress = $data->get('to_address');
             $toName = $data->get('to_name');
             $cc = $data->get('cc[]', []);
             $bcc = $data->get('bcc[]', []);
             // Send the message
             $message->from($fromAddress, $fromName);
             $message->to($toAddress, $toName)->subject($data->get('subject'));
             foreach ($cc as $address) {
                 $message->cc($address, null);
             }
             foreach ($bcc as $address) {
                 $message->bcc($address, null);
             }
         });
     } else {
         // Validation failed
         return ['success' => 0, 'status' => "Failed to validate message", 'messages' => $validator->getMessageBag()->all(), 'data' => $data, 'type' => $this->type];
     }
     if (!count(Mailer::failures())) {
         $this->sent_at = Carbon::now();
         Log::info("Sent {$this->type} email");
         return ['success' => 1, 'status' => "successfully sent message", 'data' => $data, 'type' => $this->type];
     }
     Log::info("Failed to send {$this->type} email");
     return ['success' => 0, 'status' => "failed to send message", 'messages' => "failed to send message", 'data' => $data, 'type' => $this->type];
 }
 /**
  * Return true if user has all permissions
  *
  * @param string|array $permission
  * @param bool $any
  * @return bool
  */
 public function can($permission, $any = false, $prefix = false)
 {
     $this->loadPermissions();
     if ($permission instanceof Model) {
         $permission = $permission->slug;
     }
     if ($prefix) {
         $allSlug = $this->slugPermissions->toArray();
     }
     if (is_array($permission)) {
         if ($prefix) {
             foreach ($permission as $item) {
                 if ($this->checkCanWithPrefix($allSlug, $item) === true) {
                     return true;
                 }
             }
             return false;
         } else {
             foreach ($permission as $item) {
                 if ($this->slugPermissions->search($item) === false) {
                     return false;
                 } elseif ($any === true) {
                     return true;
                 }
             }
             return true;
         }
     }
     if ($prefix) {
         return $this->checkCanWithPrefix($allSlug, $permission) !== false;
     } else {
         return $this->slugPermissions->search($permission) !== false;
     }
 }
 /**
  * @param $path
  *
  * @return array
  *
  * @throws FileManagerException
  */
 public function get()
 {
     $this->sys_path = $this->getPath()->path();
     if (!FileSystem::exists($this->sys_path)) {
         throw new FileManagerException($this, 'err_folder_not_found');
     }
     $this->readDir()->map(function ($item_name) {
         $this->content->push($this->readItem($item_name));
     });
     return $this->content->toArray();
 }
Example #4
0
 /**
  * @param string $key
  * @return static
  */
 public function getData($key = '')
 {
     $data = $this->meta->getData();
     foreach ($data as $k => $v) {
         $data->put($k, strip_tags(trim(strtr($v, $this->code->toArray()), '-_ ')));
     }
     if ($key) {
         return $data->get($key);
     } else {
         return $data;
     }
 }
 /**
  * Test that our results can be filtered down to a single author.
  */
 public function testItFiltersToASingleAuthor()
 {
     $authorResults = new Collection(['Steven King' => new Collection(), 'Stephen King' => new Collection()]);
     $actual = $this->resultCleaner->clean('Steven King', $authorResults, true);
     $expected = new Collection(['Steven King' => new Collection()]);
     $this->assertEquals($expected->toArray(), $actual->toArray());
 }
Example #6
0
 public function toArray()
 {
     $value = parent::toArray();
     $metadata = $this->metadata;
     unset($metadata['conditions']);
     return ['metadata' => $metadata, 'items' => $value];
 }
Example #7
0
 /**
  * Get all filters
  *
  * @param bool $to_array If true will return filters as array. Default set to false.
  *
  * @return array|Collection
  */
 public function getFilters($to_array = true)
 {
     if ($to_array === true) {
         return $this->filters->toArray();
     }
     return $this->filters;
 }
Example #8
0
 /**
  * Find in which collection the given dependency exists
  * @param string $dependency
  * @return array
  */
 private function findDependenciesForKey($dependency)
 {
     if ($this->css->get($dependency)) {
         return [$this->css->toArray(), 'css'];
     }
     return [$this->js->toArray(), 'js'];
 }
Example #9
0
 public function getTest()
 {
     $numberInitial = 200;
     $numberMarried = floor($numberInitial * 10 / 100);
     $genders = [Personnage::GENDER_FEMALE, Personnage::GENDER_MALE];
     $chars = new Collection();
     for ($i = 0; $i < $numberInitial; $i++) {
         $char = new Personnage();
         $chars->push($char);
         $char->setGender($genders[array_rand($genders)]);
         $char->setAge(random_int(1, 60));
         $char->setName($i);
     }
     //Create some marriages
     foreach ($chars as $char) {
         if ($char->age > 15) {
             $numberMarried--;
             $spouse = new Personnage();
             $spouse->setAge(max(15, random_int($char->age - 5, $char->age + 5)));
             $spouse->setGender($char->gender == Personnage::GENDER_MALE ? Personnage::GENDER_FEMALE : Personnage::GENDER_MALE);
             $spouse->setName("Spouse {$numberMarried}");
             $relation = new MarriedTo($spouse, $char);
             $spouse->addRelation($relation);
             $chars->push($spouse);
             //Get them some babies!
             $totalBabies = random_int(0, min(abs($char->age - $spouse->age), 5));
             $siblings = [];
             for ($i = 0; $i < $totalBabies; $i++) {
                 $child = new Personnage();
                 $child->setGender($genders[array_rand($genders)]);
                 $child->setName("Child {$numberMarried}.{$i}");
                 $relation1 = new ParentOf($char, $child);
                 $relation2 = new ParentOf($spouse, $child);
                 $char->addRelation($relation1);
                 $spouse->addRelation($relation2);
                 $chars->push($child);
                 foreach ($siblings as $sibling) {
                     $relation = new SiblingOf($sibling, $child);
                     $sibling->addRelation($relation);
                 }
                 $siblings[] = $child;
             }
         }
         if ($numberMarried <= 0) {
             break;
         }
     }
     /*$man1 = new Personnage();
             $woman1 = new Personnage();
     
             $man1->setName('man1');
             $woman1->setName('woman1');
     
             $man1->setAge(random_int(20, 50));
             $woman1->setAge(max(15,random_int($man1->age - 5, $man1->age + 5)));
     
             $married = new MarriedTo($man1, $woman1);
             $man1->addRelation($married);*/
     echo implode('<br/>', $chars->toArray());
 }
Example #10
0
 public function __construct($presenter, Collection $collection)
 {
     foreach ($collection as $key => $resource) {
         $collection->put($key, new $presenter($resource));
     }
     $this->items = $collection->toArray();
 }
Example #11
0
 /**
  * @param Film|Collection $item
  * @return array
  */
 public function transform($item)
 {
     if ($item instanceof Film) {
         return $item->toArray();
     }
     return parent::transform($item);
 }
Example #12
0
 /**
  * @param \Illuminate\Support\Collection $rules
  * @param \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Relations\Relation|\Illuminate\Database\Query\Builder $query
  * @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Relations\Relation|\Illuminate\Database\Query\Builder
  */
 protected function run($rules, $query)
 {
     $query = $query->where(function ($q) use($rules) {
         $this->rules($q, $rules->toArray());
     });
     //echo $query->toSql(); exit;
     return $query;
 }
Example #13
0
 /**
  * Compile table footer contents.
  *
  * @return array
  */
 private function compileTableFooter()
 {
     $footer = [];
     foreach ($this->collection->toArray() as $row) {
         $footer[] = '<th>' . $row['footer'] . '</th>';
     }
     return $footer;
 }
 /**
  * Convert a value to XML.
  *
  * @param Collection $value
  * @param SimpleXMLElement $element
  * @return SimpleXMLElement
  * @throws CantConvertValueException
  */
 public function convert($value, SimpleXMLElement $element) : SimpleXMLElement
 {
     if (!$value instanceof Collection) {
         throw new CantConvertValueException("Value is not a collection.");
     }
     // Hand off an array form of the collection to another converter.
     return Xml::convert($value->toArray(), $element);
 }
Example #15
0
 public function validate(Collection $attrs)
 {
     $check = $this->validator->make($attrs->toArray(), $this->policy->createRules());
     if ($check->fails()) {
         $this->log->debug('Action create by email failed validation.', $check->errors()->all());
         return false;
     }
     return true;
 }
 public function __construct($presenter, Paginator $paginator)
 {
     $this->paginator = $paginator;
     $collection = new Collection();
     foreach ($this->paginator as $key => $resource) {
         $collection->put($key, new $presenter($resource));
     }
     $this->items = $collection->toArray();
 }
Example #17
0
 /**
  * Get defaults settings.
  *
  * @param string|null $key A setting key (optional)
  *
  * @return array
  *
  * @throws \Subbly\Api\Service\Exception
  *
  * @api
  */
 public function defaults($key = null)
 {
     if (is_string($key)) {
         if (!$this->has($key)) {
             throw new Exception(sprintf(Exception::SETTING_KEY_NOT_EXISTS, $key));
         }
         return $this->defaults->offsetGet($key);
     }
     return $this->defaults->toArray();
 }
Example #18
0
 /**
  * @param $endPoint
  * @param Collection $data
  * @return \Psr\Http\Message\ResponseInterface
  * @throws RobinSendFailedException
  */
 private function post($endPoint, Collection $data)
 {
     try {
         return $this->client->post($endPoint, ['json' => $data->toArray()]);
     } catch (ClientException $exception) {
         $sendFailedException = new RobinSendFailedException();
         $sendFailedException->setResponse($exception->getResponse());
         throw $sendFailedException;
     }
 }
Example #19
0
 /**
  * Mutate an XML element based on the given data.
  *
  * @param Collection $data
  * @param SimpleXMLElement $element
  * @param mixed $providedKey
  * @return SimpleXMLElement The new element.
  */
 protected function prepareElement(Collection $data, SimpleXMLElement $element, $providedKey = null) : SimpleXMLElement
 {
     foreach ($data->toArray() as $key => $value) {
         if (is_array($value)) {
             $this->prepareElement(collect($value), $element->addChild(is_numeric($key) ? $providedKey ?: $this->intelligent_key($value) : $key), str_singular(is_numeric($key) ? $providedKey ?: $this->intelligent_key($value) : $key));
         } else {
             $element->addChild(is_numeric($key) ? $providedKey ?: $this->intelligent_key($value) : $key, $value);
         }
     }
     return $element;
 }
Example #20
0
 /**
  * @param \Notadd\Foundation\Extension\ExtensionManager $manager
  */
 public function fire(ExtensionManager $manager)
 {
     $paths = $manager->getExtensionPaths();
     $list = new Collection();
     $settings = $this->container->make(SettingsRepository::class);
     $this->info('Extensions list:');
     $paths->each(function ($path, $key) use($list, $settings) {
         $list->push([$key, $path, $settings->get('extension.' . $key . '.installed') ? 'Yes' : 'No']);
     });
     $this->table($this->headers, $list->toArray());
 }
Example #21
0
 /**
  * Returns a new table of all of the given articles.
  *
  * @param Collection $articles
  *
  * @return \Orchestra\Contracts\Html\Builder
  */
 public function table(Collection $articles)
 {
     return $this->table->of('technology.feed', function (TableGrid $table) use($articles) {
         $table->rows($articles->toArray());
         $table->column('title')->value(function ($article) {
             return $article->title;
         });
         $table->column('description')->value(function ($article) {
             return str_limit($article->description);
         });
     });
 }
Example #22
0
 /**
  * Execute the query and return the raw results.
  *
  * @throws WP_ErrorException
  *
  * @return array
  */
 protected function query()
 {
     if ($this->model) {
         $this->set('taxonomy', $this->model->taxonomy)->set('fields', 'all');
     } elseif ($this->taxonomy) {
         $this->set('taxonomy', $this->taxonomy);
     }
     if (is_wp_error($terms = get_terms($this->query->toArray()))) {
         throw new WP_ErrorException($terms);
     }
     return $terms;
 }
 /**
  * Execute the job.
  *
  * @param User $user
  * @param Role $role
  * @return String
  */
 public function handle(User $user, Role $role)
 {
     /**
      * Find Role
      */
     $role = $role->where('id', $this->role)->orWhere('name', $this->role)->firstOrFail();
     /**
      * Create User, Set Role and Token
      */
     $user = $user->create($this->request->toArray());
     $user->setAttribute('api_token', $token = dispatch(new GenerateTokenJob($user)));
     $user->setAttribute('newsletter', filter_var($this->request->get('newsletter', false), FILTER_VALIDATE_BOOLEAN));
     $user->roles()->attach($role);
     /*$user->country()->associate($this->country_id);
       $user->age()->associate($this->age_id);*/
     $user->save();
     /**
      * Announce UserWasCreated
      */
     event(new UserWasCreated($user));
     return $user;
 }
 /**
  * @param \Illuminate\Support\Collection $results
  * @return array
  */
 protected function totals($results)
 {
     $return = new Collection();
     $results->map(function ($results, $provider) use($return) {
         $totals = new Collection();
         foreach ($results as $scope => $resultSet) {
             $totals[$scope] = array_sum(array_values($resultSet));
         }
         $totals['_total'] = array_sum($totals->toArray());
         $return[$provider] = $totals;
     });
     return $return;
 }
 /**
  * Check if codes are all unique
  * @return string
  */
 private function checkDatabase()
 {
     /**
      * Check Against Database to find duplicated Code
      */
     /** @var Collection $duplicated */
     $duplicated = $this->product->codes()->whereIn('code', $this->codes->toArray())->get();
     if (!$duplicated->isEmpty()) {
         $duplicated->each(function ($duplicated) {
             $this->regenerate($duplicated->code);
         });
     }
 }
Example #26
0
 public function toArray()
 {
     if ($this->hasTransForm) {
         return $this->attribute->toArray();
     } else {
         if ($this->transformBeforSet) {
             $this->setAttribute();
             return $this->attribute->toArray();
         } else {
             $this->applyTransform();
             return $this->results->toArray();
         }
     }
 }
Example #27
0
File: Role.php Project: znck/trust
 protected function collectPermissions($permission)
 {
     if (is_string($permission)) {
         $permission = app(PermissionContract::class)->whereSlug($permission)->first();
     }
     if (is_array($permission) or $permission instanceof Collection) {
         $permission = new Collection($permission);
         if (is_string($permission->first())) {
             return app(PermissionContract::class)->whereIn('slug', $permission->toArray())->get();
         } elseif ($permission->first() instanceof PermissionContract) {
             return $permission;
         }
     } elseif ($permission instanceof PermissionContract) {
         return $permission;
     }
     return null;
 }
Example #28
0
 public function remove()
 {
     $ids = Session::get('compare_cart');
     if (Input::has('id')) {
         $remove_id = Input::get('id');
         $ids = array_where($ids, function ($k, $v) use($remove_id) {
             return $v != $remove_id;
         });
         Session::put('compare_cart', $ids);
     }
     // Find TourSchedules
     if (!empty($ids)) {
         $tour_schedules = \App\TourSchedule::with('tour', 'tour.travel_agent', 'tour.travel_agent.images')->whereIn('id', $ids)->published()->orderBy('departure')->get();
     } else {
         $tour_schedules = new Collection();
     }
     return Response::json(['data' => $tour_schedules->toArray()], 200);
 }
Example #29
0
 protected function appendLimitingOptions($q, QueryFilter $filter)
 {
     $q = $q->take($filter->get('take'));
     if ($after = $filter->get('after')) {
         $q = $q->where('id', '>', $after->id);
     }
     if ($before = $filter->get('before')) {
         $q = $q->where('id', '<', $before->id);
     }
     if ($only = $filter->get('only')) {
         $onlyFilter = new Collection(explode(',', $only));
         $q = $q->whereIn('notification_type', $onlyFilter->toArray());
     }
     if ($except = $filter->get('except')) {
         $exceptFilter = new Collection(explode(',', $except));
         $q = $q->whereNotIn('notification_type', $exceptFilter->toArray());
     }
     return $q;
 }
Example #30
0
 function getDiffFiles(array $files, \Illuminate\Support\Collection $seeded, \LaravelSeed\Contracts\ProviderInterface $provider)
 {
     $edited = [];
     array_map(function ($seed) use($files, &$edited, $provider) {
         $fullPath = getFullPathSource($seed->name, $provider);
         if (!in_array($fullPath, $files)) {
             return false;
         }
         $key = array_search($fullPath, $files);
         $filemtime = filemtime($files[$key]);
         if ($filemtime > $seed->hash) {
             $edited[] = $fullPath;
         }
         return false;
     }, $seeded->toArray());
     $diff = [];
     array_walk($files, function ($file) use($seeded, &$diff) {
         $filename = pathinfo($file)['filename'];
         if (!$seeded->contains('name', $filename)) {
             $diff[] = $file;
         }
     });
     return array_merge($diff, $edited);
 }