get() public method

Get an item from the collection by key.
public get ( mixed $key, mixed $default = null ) : mixed
$key mixed
$default mixed
return mixed
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];
 }
Example #2
0
 /**
  * @param GrantableInterface $grantable
  * @param                    $action
  *
  * @return mixed
  */
 public function isAllow(GrantableInterface $grantable, $action)
 {
     if (is_null($this->permissions) || $this->permissions->isEmpty()) {
         $this->initialize($grantable);
     }
     return $this->permissions->get($action, false);
 }
 /**
  * @param string $key
  *
  * @return array
  */
 protected function loadRules($key)
 {
     if (!$this->rules->has($key)) {
         $this->rules->put($key, $this->loadRulesFromFile($key));
     }
     return $this->rules->get($key);
 }
Example #4
0
 /**
  * obtener una evaluacion en específico
  * @param int $id
  * @return mixed|null
  */
 public function evaluacion($id)
 {
     if ($this->buscarEvaluacion($id) === false) {
         return null;
     }
     return $this->listaEvaluaciones->get($id);
 }
Example #5
0
 public function applications()
 {
     $apps = $this->items->get('applications');
     if (is_array($apps)) {
         $apps = $this->transformToCollections($apps);
     }
     return new Collection($apps);
 }
 /**
  * @param File $image
  * @param string $prefix
  * @param String $path
  * @return string
  */
 public function moveFile(File $image, $path, $prefix = '')
 {
     $extension = $image->guessExtension();
     $code = strtoupper($this->request->get('code'));
     $fileName = $code . '-' . $prefix . '.' . $extension;
     $image->move(public_path() . $path, $fileName);
     return $path . $fileName;
 }
Example #7
0
 /**
  * Get instance of type.
  *
  * @param  string $name
  * @param  bool $fresh
  * @return \GraphQL\Type\Definition\ObjectType
  */
 public function instance($name, $fresh = false)
 {
     if (!$fresh && $this->instances->has($name)) {
         return $this->instances->get($name);
     }
     $type = $this->getType($name)->resolve();
     $instance = $type instanceof Model ? (new EloquentType($type, $name))->toType() : $type->toType();
     $this->instances->put($name, $instance);
     return $instance;
 }
Example #8
0
 /**
  * @param string|Model $model
  * @param string       $query
  * @param int|null     $perPage
  * @param string       $pageName
  *
  * @return LengthAwarePaginator|Collection
  * @throws \Exception
  */
 public function searchIn($model, $query = "", $perPage = null, $pageName = 'page')
 {
     if ($model instanceof Model) {
         $model = get_class($model);
     }
     if (!$this->models->offsetExists($model)) {
         throw new \Exception("Search engine for model [{$model}] not found");
     }
     return $this->_search([$this->models->get($model)], $query = "", $perPage = null, $pageName = 'page');
 }
Example #9
0
 /**
  * @param $provider
  *
  * @return Providers\ProvidersInterface;
  * @throws \Exception
  */
 private function loadProvider($provider)
 {
     if (!isset($this->providersAvailable[$provider])) {
         throw new \Exception('Lavatar provider ' . $provider . ' does not exist.');
     }
     $this->providersLoadeds[$provider] = app($this->providersAvailable[$provider]);
     $options = $this->config->get($provider, array());
     $this->providersLoadeds[$provider]->setupOptions($options);
     return $this->providersLoadeds[$provider];
 }
 public function it_should_generate_a_module(Filesystem $filesystem, Mustache_Engine $mustache, Collection $c)
 {
     $filesystem->get('template.stub')->shouldBeCalled()->willReturn('template');
     $filesystem->put('js/modules/tacos/index.js', 'output')->shouldBeCalled();
     $mustache->render('template', ['model_path' => 'modules/tacos/models/taco', 'model' => 'Taco', 'collection_path' => 'modules/tacos/collections/tacos', 'collection' => 'TacoCollection', 'view_path' => 'modules/tacos/views/taco_view', 'view' => 'TacoView'])->shouldBeCalled()->willReturn('output');
     $c->get('model')->willReturn(new BackboneComponent('', 'modules/tacos/models/taco', 'Taco'))->shouldBeCalled();
     $c->get('view')->willReturn(new BackboneComponent('', 'modules/tacos/views/taco_view', 'TacoView'))->shouldBeCalled();
     $c->get('collection')->willReturn(new BackboneComponent('', 'modules/tacos/collections/tacos', 'TacoCollection'))->shouldBeCalled();
     $f = new BackboneComponent('js/modules/tacos/index.js', 'index', 'Index');
     $this->generate($f, 'template.stub', $c);
 }
Example #11
0
 /**
  * Process the payload.
  * @param Collection $payload
  * @return Collection
  */
 public function process($payload)
 {
     $series = $payload->get('series');
     $game = $series->game;
     $creator = $payload->get('creator');
     $creator->persist();
     $creator->relatesToGame($game);
     $series->creator()->associate($creator->model);
     $creator->model->touch();
     return $payload;
 }
Example #12
0
 /**
  * Add a new Item (or edit an existing item) to the Group
  *
  * @param string   $name
  * @param callable $callback
  *
  * @return Item
  */
 public function item($name, Closure $callback = null)
 {
     if ($this->items->has($name)) {
         $item = $this->items->get($name);
     } else {
         $item = $this->container->make('Maatwebsite\\Sidebar\\Item');
         $item->name($name);
     }
     $this->call($callback, $item);
     $this->addItem($item);
     return $item;
 }
Example #13
0
 /**
  * Get instance of connection type.
  *
  * @param  string $name
  * @param  string|null $parent
  * @param  bool $fresh
  * @return \Nuwave\Lighthouse\Support\Definition\Fields\ConnectionField
  */
 public function instance($name, $parent = null, $fresh = false)
 {
     $instanceName = $this->instanceName($name);
     $typeName = $this->typeName($name);
     if (!$fresh && $this->instances->has($instanceName)) {
         return $this->instances->get($instanceName);
     }
     $key = $parent ? $parent . '.' . $instanceName : $instanceName;
     $nodeType = $this->getSchema()->typeInstance($typeName);
     $instance = $this->getInstance($name, $nodeType);
     $this->instances->put($key, $instance);
     return $instance;
 }
 /**
  * @return \Spatie\SlashCommand\Handlers\BaseHandler
  *
  * @throws \Spatie\SlashCommand\Exceptions\RequestCouldNotBeHandled
  */
 protected function determineHandler()
 {
     $handler = collect($this->config->get('handlers'))->map(function (string $handlerClassName) {
         if (!class_exists($handlerClassName)) {
             throw InvalidHandler::handlerDoesNotExist($handlerClassName);
         }
         return new $handlerClassName($this->request);
     })->filter(function (HandlesSlashCommand $handler) {
         return $handler->canHandle($this->request);
     })->first();
     if (!$handler) {
         throw RequestCouldNotBeHandled::noHandlerFound($this->request);
     }
     return $handler;
 }
Example #15
0
 /**
  * Parse parameters and return the altering classes
  *
  * @param  mixed $parameters
  * @return \Illuminate\Support\Collection
  */
 public function parse($parameters)
 {
     // Fetch parameters. If the variable is an array nothing will happen.
     // If it's a string, it will be tokenized and will return as an array.
     $params = $this->getParameters($parameters);
     $collection = new Collection();
     foreach ($params as $token => $value) {
         // create the manipulator
         $manipulator = $this->createManipulator($token);
         $className = get_class($manipulator);
         // get the classname
         if ($collection->has($className)) {
             $manipulator = $collection->get($className);
         }
         // set values
         if ($token === self::REQUEST_PARAM_WIDTH) {
             $manipulator->setWidth($value);
         } elseif ($token === self::REQUEST_PARAM_HEIGHT) {
             $manipulator->setHeight($value);
         }
         // put in the colllection
         $collection->put($className, $manipulator);
     }
     return $collection;
 }
Example #16
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 #17
0
 /**
  * Returns the group MenuPresence instance in the menuGroup tree by dot notation key.
  * Recursive.
  *
  * @param string                     $dotKey
  * @param null|MenuPresenceInterface $parent
  * @return false|MenuPresenceInterface
  */
 protected function getDotMenuGroupPresence($dotKey, $parent = null)
 {
     $keys = explode('.', $dotKey);
     $firstKey = array_shift($keys);
     // For the top level, find the outer group and start recursion, or
     // return the outer group if it is not a nested key.
     if (!$parent) {
         $parent = $this->menuGroups->get($firstKey);
         if (!$parent) {
             return false;
         }
         if (!count($keys)) {
             return $parent;
         }
         return $this->getDotMenuGroupPresence(implode('.', $keys), $parent);
     }
     // For nested groups, find the relevant child and keep going deeper
     // until we get it.
     if (!$parent->children()) {
         return false;
     }
     if (!count($keys)) {
         return $parent->children()[$firstKey];
     }
     return $this->getDotMenuGroupPresence(implode('.', $keys), $parent->children()[$firstKey]);
 }
Example #18
0
 /**
  * Get the value of a field
  *
  * @param string $field The field's name
  *
  * @return mixed
  */
 public function get($field, $fallback = null)
 {
     // Plain array
     if (is_array($this->items) and !str_contains($field, '[')) {
         return parent::get($field, $fallback);
     }
     // Transform the name into an array
     $value = $this->items;
     $field = $this->parseFieldAsArray($field);
     // Dive into the model
     foreach ($field as $relationship) {
         // Get attribute from model
         if (!is_array($value)) {
             $value = $this->getAttributeFromModel($value, $relationship, $fallback);
             if ($value === $fallback) {
                 break;
             }
             continue;
         }
         // Get attribute from model
         if (array_key_exists($relationship, $value)) {
             $value = $value[$relationship];
         } else {
             foreach ($value as $key => $submodel) {
                 $value[$key] = $this->getAttributeFromModel($submodel, $relationship, $fallback);
             }
         }
     }
     return $value;
 }
 /**
  * Get an addon.
  *
  * @param  mixed $key
  * @param  null  $default
  * @return Addon|mixed|null
  */
 public function get($key, $default = null)
 {
     if (!($addon = parent::get($key, $default))) {
         return $this->findBySlug($key);
     }
     return $addon;
 }
Example #20
0
 /**
  * @return void
  */
 public function preInstall()
 {
     if ($this->extension->has('autoload')) {
         $autoload = collect($this->extension->get('autoload'));
         $autoload->has('classmap') && collect($autoload->get('classmap'))->each(function ($value) {
             $path = str_replace($this->container->basePath() . '/', '', realpath($this->path . DIRECTORY_SEPARATOR . $value)) . '/';
             if (!in_array($path, $this->backup['autoload']['classmap'])) {
                 $this->backup['autoload']['classmap'][] = $path;
             }
         });
         $autoload->has('files') && collect($autoload->get('files'))->each(function ($value) {
             $path = str_replace($this->container->basePath() . '/', '', realpath($this->path . DIRECTORY_SEPARATOR . $value));
             if (!in_array($path, $this->backup['autoload']['files'])) {
                 $this->backup['autoload']['files'][] = $path;
             }
         });
         $autoload->has('psr-0') && collect($autoload->get('psr-0'))->each(function ($value, $key) {
             $path = str_replace($this->container->basePath() . '/', '', realpath($this->path . DIRECTORY_SEPARATOR . $value)) . '/';
             $this->backup['autoload']['psr-0'][$key] = $path;
         });
         $autoload->has('psr-4') && collect($autoload->get('psr-4'))->each(function ($value, $key) {
             $path = str_replace($this->container->basePath() . '/', '', realpath($this->path . DIRECTORY_SEPARATOR . $value)) . '/';
             $this->backup['autoload']['psr-4'][$key] = $path;
         });
     }
     if ($this->extension->has('require')) {
         $require = collect($this->extension->get('require'));
         $require->each(function ($version, $name) {
             $this->backup['require'][$name] = $version;
         });
     }
 }
Example #21
0
 /**
  * Process the payload.
  * @param Collection $payload
  * @return Collection
  */
 public function process($payload)
 {
     $series = $payload->get('series');
     $series->touch();
     $series->save();
     return $payload;
 }
Example #22
0
 /**
  * Returns a module by key.
  *
  * @param string $key
  * @return ModuleInterface|false
  */
 public function get($key)
 {
     if (!$this->has($key)) {
         return false;
     }
     return $this->modules->get($key);
 }
Example #23
0
 /**
  * @test
  * @group failing
  */
 public function itCanPaginateConnectionWithConnectionType()
 {
     $id = $this->encodeGlobalId(UserStubConnectionType::class, $this->user->id);
     $first = 2;
     $query = $this->getQuery($id, $first);
     $graphql = app('graphql');
     $graphql->schema()->type('user', UserStubConnectionType::class);
     $graphql->schema()->type('task', TaskStubType::class);
     $data = $this->executeQuery($query);
     $edges = array_get($data, 'data.node.tasks.edges');
     $this->assertCount(2, $edges);
     $this->assertEquals($this->tasks->get(0)->title, array_get($edges, '0.node.title'));
     $this->assertEquals($this->tasks->get(1)->title, array_get($edges, '1.node.title'));
     $this->assertNotNull(array_get($edges, '1.cursor'));
     $after = array_get($edges, '1.cursor');
     $query = $this->getQuery($id, $first, $after);
     $data = $this->executeQuery($query);
     $edges = array_get($data, 'data.node.tasks.edges');
     $this->assertCount(2, $edges);
     $this->assertEquals($this->tasks->get(2)->title, array_get($edges, '0.node.title'));
     $this->assertEquals($this->tasks->get(3)->title, array_get($edges, '1.node.title'));
     $after = array_get($edges, '1.cursor');
     $query = $this->getQuery($id, $first, $after);
     $data = $this->executeQuery($query);
     $edges = array_get($data, 'data.node.tasks.edges');
     $this->assertCount(2, $edges);
     $this->assertEquals($this->tasks->get(4)->title, array_get($edges, '0.node.title'));
     $this->assertEquals($this->tasks->get(5)->title, array_get($edges, '1.node.title'));
 }
Example #24
0
 protected function setApproved($name, array $fields = [])
 {
     $columns = [];
     foreach ($fields as $key => $value) {
         $columns[] = is_string($key) && !is_numeric($key) ? $key : $value;
     }
     $settings = $this->allowed->get($name);
     $custom = false;
     if (is_array($settings) && isset($settings['custom'])) {
         $custom = $settings['custom'];
     }
     if (count($columns) > 0) {
         if ($custom instanceof \Closure) {
             $config = $this->config;
             $this->approved[$name] = function ($query) use($columns, $custom, $config) {
                 $query->select($columns);
                 $custom($config, $query);
             };
         } else {
             $this->approved[$name] = function ($query) use($columns) {
                 $query->select($columns);
             };
         }
     } else {
         $this->approved[] = $name;
     }
 }
Example #25
0
 /**
  * @param $tenant
  *
  * @throws TenantColumnUnknownException
  *
  * @return mixed
  */
 public function getTenantId($tenant)
 {
     if (!$this->hasTenant($tenant)) {
         throw new TenantColumnUnknownException('$tenant must be a string key or an instance of \\Illuminate\\Database\\Eloquent\\Model');
     }
     return $this->tenants->get($this->getTenantKey($tenant));
 }
Example #26
0
 /**
  * project
  *
  * @param $name
  * @return \Codex\Codex\Project
  */
 public function getProject($name)
 {
     if (!$this->hasProject($name)) {
         throw new \InvalidArgumentException("Project [{$name}] could not be found in [{$this->rootDir}]");
     }
     return $this->projects->get($name);
 }
Example #27
0
 /**
  * Get instance of edge type.
  *
  * @param  string $name
  * @param  bool $fresh
  * @param  ObjectType|null $type
  * @return \GraphQL\Type\Definition\ObjectType|null
  */
 public function instance($name, $fresh = false, ObjectType $type = null)
 {
     $instanceName = $this->instanceName($name);
     if (!$fresh && $this->instances->has($instanceName)) {
         return $this->instances->get($instanceName);
     }
     if ($name instanceof ConnectionEdge) {
         $instance = $this->createEdge($name);
         $this->instances->put($instanceName, $instance);
         return $instance;
     } elseif ($type) {
         $instance = $this->createInstance($name, $type);
         $this->instances->put($name, $instance);
         return $instance;
     }
     return null;
 }
Example #28
0
 /**
  * @param $key
  * @param $resource
  * @return mixed
  */
 private function getResource($key, $resource)
 {
     if ($this->notFetched($key)) {
         $result = $this->client->retrieve($resource, $key);
         $this->fetched->put($key, $result);
     }
     return $this->fetched->get($key);
 }
Example #29
0
 /**
  * @param $key
  * @param $amount
  * @param $item
  */
 protected function addExistsIntoItems($key, $amount, $item)
 {
     $temp = $this->_items->get($key);
     $temp['amount'] += $amount;
     $this->_items->forget($key);
     $this->_items->push($temp);
     $this->_totalPrice += $amount * $item->getPrice();
 }
Example #30
0
 /**
  * @param TransactionJournal $entry
  */
 public function addOrCreateIncome(TransactionJournal $entry)
 {
     $accountId = $entry->account_id;
     if (!$this->incomes->has($accountId)) {
         $newObject = new stdClass();
         $newObject->amount = strval(round($entry->amount, 2));
         $newObject->name = $entry->name;
         $newObject->count = 1;
         $newObject->id = $accountId;
         $this->incomes->put($accountId, $newObject);
     } else {
         bcscale(2);
         $existing = $this->incomes->get($accountId);
         $existing->amount = bcadd($existing->amount, $entry->amount);
         $existing->count++;
         $this->incomes->put($accountId, $existing);
     }
 }