has() public method

Determine if an item exists in the collection by key.
public has ( mixed $key ) : boolean
$key mixed
return boolean
Example #1
0
 /**
  * @param WithInterface|DataInterface|ModelInterface $config
  * @return mixed
  */
 public function apply($config)
 {
     if (!($config instanceof WithInterface && $config instanceof DataInterface && $config instanceof ModelInterface)) {
         return;
     }
     if ($config->with()->isEmpty()) {
         return;
     }
     $this->config = $config;
     $this->allowed = $config->with();
     foreach ($this->allowed as $key => $value) {
         if (is_numeric($key)) {
             $this->allowed->forget($key)->put($value, '*');
         }
     }
     foreach (explode('|', $config->data()->get('with', '')) as $with) {
         $parts = explode(':', $with);
         if (count($parts) == 0) {
             continue;
         }
         if (!$this->allowed->has($parts[0])) {
             continue;
         }
         $this->processWith($parts[0], isset($parts[1]) ? $parts[1] : '');
     }
     if (count($this->approved) > 0) {
         $config->model($config->model()->with($this->approved));
     }
 }
 /**
  * @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 #3
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 #4
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;
 }
 /**
  * @param $records
  *
  * @return mixed
  */
 public function mutateRecords($records)
 {
     $_ignored = ['id', 'sortorder', 'updated_at', 'created_at'];
     foreach ($records as $model) {
         $toLoop = array_except($model->toArray(), $_ignored);
         foreach ($toLoop as $k => $r) {
             if ($this->attributes->has($k)) {
                 $model->{$k} = $this->attributes[$k]->getDisplayValue($model);
             }
         }
     }
     return $records;
 }
 /**
  * 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;
 }
Example #7
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 #8
0
 /**
  * Get single filter by key
  *
  * @param $key
  * @param string $default_value Default value if key is not found
  *
  * @return mixed|string
  */
 public function getFilter($key, $default_value = '')
 {
     if ($this->filters->has($key)) {
         return $this->filters[$key];
     }
     return $default_value;
 }
Example #9
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;
 }
 /**
  * Returns the user throttles collection.
  *
  * @param  \Cartalyst\Sentinel\Users\UserInterface  $user
  * @return \Illuminate\Support\Collection
  */
 protected function getUserThrottles(UserInterface $user)
 {
     if (!$this->userThrottles->has($user->getUserId())) {
         $this->userThrottles[$user->getUserId()] = $this->loadUserThrottles($user);
     }
     return $this->userThrottles[$user->getUserId()];
 }
Example #11
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 #12
0
 public function __call($name, $arguments)
 {
     $prefix = substr($name, 0, 3);
     $property = snake_case(substr($name, 3));
     if ($prefix === 'get' && $this->attributes->has($property)) {
         return $this->get($property);
     }
     throw new \InvalidArgumentException();
 }
Example #13
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);
     }
 }
 /**
  * Removes Criteria, but only for the next call, resets to default afterwards
  * Note that this does NOT work for specific criteria exclusively, it resets
  * to default for ALL Criteria.
  *
  * In effect, this adds a NullCriteria to onceCriteria by key, disabling any criteria
  * by that key in the normal criteria list.
  *
  * @param string $key
  * @return $this
  */
 public function removeCriteriaOnce($key)
 {
     // if not present in normal list, there is nothing to override
     if (!$this->criteria->has($key)) {
         return $this;
     }
     // override by key with Null-value
     $this->onceCriteria->put($key, new NullCriteria());
     return $this;
 }
Example #15
0
 /**
  * Mass-assign options for given fields.
  * @param $array array column=>options
  * @return $this
  */
 public function setOptions($array)
 {
     foreach ($array as $field => $options) {
         if (!$this->fields->has($field)) {
             continue;
         }
         $this->getField($field)->options = $options;
     }
     return $this;
 }
Example #16
0
 /**
  * Ask the user what they would like to register with the application
  *
  * @return void
  */
 public function whatWouldYouLikeToRegister()
 {
     $choices = $this->registrars->keys();
     $choices[] = 'No more';
     $registerType = $this->askWithCompletion('What would you like to register? (' . implode(', ', $choices->toArray()) . ')', $choices->toArray(), $choices->first());
     if ($registerType === 'No more') {
         foreach ($this->registrars as $registrar) {
             $registrar->afterRegistration();
         }
         $this->updateEnvFile();
         return;
     }
     if ($registerType == '' || !$this->registrars->has($registerType)) {
         $this->error('Unable to register that. Please try again.');
         $this->whatWouldYouLikeToRegister();
         return;
     }
     $this->registrars->get($registerType)->register();
     $this->whatWouldYouLikeToRegister();
 }
 /**
  * Process the payload.
  * @param Collection $payload
  * @return Collection
  */
 public function process($payload)
 {
     $series = $payload->pull('series');
     $series->persist();
     if ($payload->has('game')) {
         $game = $payload->get('game');
         $series->relatesToGame($game);
     }
     $payload->put('series', $series->model);
     return $payload;
 }
Example #18
0
 /**
  * Fetch all the queues inside the 'queues' namespace with the delayed and
  * reserved.
  *
  * @return \Illuminate\Support\Collection
  */
 public function getAll()
 {
     $collection = new Collection();
     $keys = $this->database->keys($this->namespace . ':*');
     foreach ($keys as $key) {
         list($namespace, $name) = explode(':', $key);
         if (!$collection->has($name)) {
             $collection->put($name, $this->get($name));
         }
     }
     return $collection;
 }
Example #19
0
 /**
  * Get order by field name
  *
  * @return string
  */
 public function getOrderBy()
 {
     $by = $this->getOrderByField();
     if ($this->constraints->has($by)) {
         $constraint = $this->constraints->get($by);
         if ($constraint instanceof Closure) {
             return $constraint;
         } else {
             return $by;
         }
     }
     return '';
 }
Example #20
0
 /**
  * Add new settings meta info.
  *
  * @param Meta $meta
  */
 public function addMeta(Meta $meta)
 {
     $group = $meta->getGroup();
     if (!$this->groups->has($group)) {
         $this->groups->put($group, new Collection());
     }
     if ($this->all->has($meta->getName())) {
         throw new \RuntimeException('Settings with name `' . $meta->getName() . '` already exists .');
     }
     $this->all->put($meta->getName(), $meta);
     //$this->groups->get($group);
     $this->groups->get($group)->put($meta->getName(), $meta);
 }
Example #21
0
 /**
  * @param TransactionJournal $entry
  */
 public function addOrCreateExpense(TransactionJournal $entry)
 {
     bcscale(2);
     $accountId = $entry->account_id;
     $amount = strval(round($entry->amount, 2));
     if (bccomp('0', $amount) === -1) {
         $amount = bcmul($amount, '-1');
     }
     if (!$this->expenses->has($accountId)) {
         $newObject = new stdClass();
         $newObject->amount = $amount;
         $newObject->name = $entry->name;
         $newObject->count = 1;
         $newObject->id = $accountId;
         $this->expenses->put($accountId, $newObject);
     } else {
         $existing = $this->expenses->get($accountId);
         $existing->amount = bcadd($existing->amount, $amount);
         $existing->count++;
         $this->expenses->put($accountId, $existing);
     }
 }
Example #22
0
 /**
  * @param TransactionJournal $entry
  */
 public function addOrCreateIncome(TransactionJournal $entry)
 {
     // add each account individually:
     $sources = TransactionJournal::sourceTransactionList($entry);
     foreach ($sources as $transaction) {
         $amount = strval($transaction->amount);
         $account = $transaction->account;
         $amount = bcmul($amount, '-1');
         $object = new stdClass();
         $object->amount = $amount;
         $object->name = $account->name;
         $object->count = 1;
         $object->id = $account->id;
         // overrule some properties:
         if ($this->incomes->has($account->id)) {
             $object = $this->incomes->get($account->id);
             $object->amount = bcadd($object->amount, $amount);
             $object->count++;
         }
         $this->incomes->put($account->id, $object);
     }
 }
Example #23
0
 /**
  * agregar nuevo "otro" tratamiento al plan
  * @param int $indice
  * @param OtroTratamiento $tratamiento
  */
 public function agregarOtroTratamiento($indice, OtroTratamiento $tratamiento)
 {
     if (is_null($this->listaOtrosTratamientos)) {
         $this->listaOtrosTratamientos = new Collection();
     }
     /*if (count($this->listaTratamientos) === 2) {
           throw new \Exception('Solo se permiten hasta dos tratamientos por diente');
       }*/
     // si ya está ocupada la posición, la elimina para permitir agregar uno nuevo
     if ($this->listaOtrosTratamientos->has($indice)) {
         $this->listaOtrosTratamientos->forget($indice);
     }
     $this->listaOtrosTratamientos->put($indice, $tratamiento);
 }
Example #24
0
 /**
  * Add another Menu instance and combined the two
  * Groups with the same name get combined, but
  * inherit each other's items
  *
  * @param Menu $menu
  *
  * @return Menu $menu
  */
 public function add(Menu $menu)
 {
     foreach ($menu->getGroups() as $group) {
         if ($this->groups->has($group->getName())) {
             $existingGroup = $this->groups->get($group->getName());
             $group->hideHeading(!$group->shouldShowHeading());
             foreach ($group->getItems() as $item) {
                 $existingGroup->addItem($item);
             }
         } else {
             $this->addGroup($group);
         }
     }
     return $this;
 }
Example #25
0
 /**
  * @param TransactionJournal $entry
  */
 public function addOrCreateExpense(TransactionJournal $entry)
 {
     // add each account individually:
     $destinations = TransactionJournal::destinationTransactionList($entry);
     foreach ($destinations as $transaction) {
         $amount = strval($transaction->amount);
         $account = $transaction->account;
         if (bccomp('0', $amount) === -1) {
             $amount = bcmul($amount, '-1');
         }
         $object = new stdClass();
         $object->amount = $amount;
         $object->name = $account->name;
         $object->count = 1;
         $object->id = $account->id;
         // overrule some properties:
         if ($this->expenses->has($account->id)) {
             $object = $this->expenses->get($account->id);
             $object->amount = bcadd($object->amount, $amount);
             $object->count++;
         }
         $this->expenses->put($account->id, $object);
     }
 }
Example #26
0
 /**
  * Instantiates and returns the asked resource.
  * @param string The resource name
  * @throws \Snorlax\Exception\ResourceNotImplemented If the resource is not available
  * @return \Snorlax\Resource The instantiated resource
  */
 public function getResource($resource)
 {
     if ($this->cache->has($resource)) {
         return $this->cache->get($resource);
     }
     if (!$this->resources->has($resource)) {
         throw new ResourceNotImplemented($resource);
     }
     $params = $this->resources->get($resource);
     $instance = $params['instance'];
     if (is_null($instance)) {
         $class = $params['class'];
         $instance = new $class($this->client);
     }
     return $this->cache[$resource] = $instance;
 }
Example #27
0
 /**
  * Get instance of connection type.
  *
  * @param  string $name
  * @param  Closure|string|null $resolve
  * @param  boolean $fresh
  * @return mixed
  */
 public function connection($name, $resolve = null, $fresh = false)
 {
     $this->checkType($name);
     if ($resolve && !$resolve instanceof Closure) {
         $resolve = function ($root, array $args, ResolveInfo $info) use($resolve) {
             return $this->resolveConnection($root, $args, $info, $resolve);
         };
     }
     if (!$fresh && $this->connectionInstances->has($name)) {
         $field = $this->connectionInstances->get($name);
         $field['resolve'] = $resolve;
         return $field;
     }
     $field = $this->connectionField($name, $resolve);
     $this->connectionInstances->put($name, $field);
     return $field;
 }
 /**
  * @param Column $column
  * @param Collection $foreignKeyColumns
  * @param Collection $foreignTables
  * @param Collection $indexes
  * @return ColumnInterface
  */
 protected function buildColumn(Column $column, Collection $foreignKeyColumns, Collection $foreignTables, Collection $indexes)
 {
     $uniqued = $indexes->filter(function (Index $index) use($column) {
         return $index->getColumns()[0] == $column->getName() && $index->isUnique();
     })->count() > 0;
     if ($column->getAutoincrement()) {
         return new ColumnAutoincrement($column, null, null, $uniqued);
     } else {
         if ($foreignKeyColumns->has($column->getName())) {
             $table = $foreignKeyColumns->get($column->getName());
             return new ColumnSelect($column, $table, $foreignTables->get($table), $uniqued);
         } else {
             if ($column->getType()->getName() == Type::INTEGER) {
                 return new ColumnNumericText($column, null, null, $uniqued);
             } else {
                 return new ColumnText($column, null, null, $uniqued);
             }
         }
     }
 }
Example #29
0
 /**
  * Process the payload.
  * @param Collection $payload
  * @return Collection
  */
 public function process($payload)
 {
     $series = $payload->get('series');
     $game = $series->game;
     $creator = $payload->has('creator') ? $payload->get('creator')->model : $series->creator;
     $videos = $payload->get('videos');
     if ($payload->get('config')['mode'] === 'update') {
         $videos = $videos->reject(function ($video) {
             return $video->isPersisted();
         });
     }
     $videos->each(function ($video) use($creator, $series, $game) {
         $video->persist();
         $video->relatesToGame($game);
         $video->relatesToSeries($series);
         $video->relatesToCreator($creator);
         $video->model->touch();
     });
     return $payload;
 }
Example #30
0
 /**
  * Go
  *
  * Goes through all of the registered modules and attempts
  * to activate them. Performs checks to ensure that modules
  * that declare dependencies that have not been satisfied
  * will not be activated.
  *
  * Registers any directories with the class loader
  *
  * @return void
  */
 public function go()
 {
     $this->handlePreRegistered();
     $toActivate = $this->registeredModules->all();
     // This 'while' loop runs continuously allowing for modules
     // to be checked multiple times which allows for dependencies.
     while (count($toActivate) > 0) {
         foreach ($toActivate as $name => $module) {
             $canActivate = true;
             $dependencies = $module->dependencies();
             // If we've got dependencies, check them all to make sure all have been activated
             // before activating this particular module.
             if (!empty($dependencies)) {
                 foreach ($dependencies as $dependency) {
                     // First off, if this dependency hasn't even been register, we can never
                     // activate this module, so let's skip it and not try again.
                     if (!$this->registeredModules->has($dependency)) {
                         $canActivate = false;
                         $this->dispatcher->fire(self::EVENT_ACTIVATION_FAILED . ' ' . $name, $module);
                         unset($toActivate[$name]);
                         continue;
                     }
                     // At this point, the dependency has been registered but not activated,
                     // so let's skip this module and come back to it.
                     if (!$this->activeModules->has($dependency)) {
                         $canActivate = false;
                     }
                 }
             }
             // Now let's activate this sucka! Also, we remove it from the list
             // so we don't try to activate it again.
             if ($canActivate) {
                 $this->activeModules->put($name, $module->activate());
                 $this->dispatcher->fire(self::EVENT_ACTIVE . " {$name}", $module);
                 unset($toActivate[$name]);
             }
         }
     }
     $this->classLoader->register();
 }