put() public method

Put an item in the collection by key.
public put ( mixed $key, mixed $value )
$key mixed
$value mixed
Example #1
5
 /**
  * Add a tenant to scope by.
  *
  * @param string|Model $tenant
  * @param mixed|null   $id
  */
 public function addTenant($tenant, $id = null)
 {
     if (func_num_args() == 1) {
         $id = $tenant->getKey();
     }
     $this->tenants->put($this->getTenantKey($tenant), $id);
 }
Example #2
0
 /**
  * @param SearchConfiguratorInterface $config
  *
  * @return $this
  */
 public function register(SearchConfiguratorInterface $config = null)
 {
     /** @var SearchEngineInterface $engine */
     $this->models->put(get_class($config->getModel()), $engine = $this->manager->driver($config->engine()));
     $engine->setConfigurator($config);
     return $this;
 }
 /**
  * Run the actual import
  *
  * @return Collection
  */
 public function createImportEntries() : Collection
 {
     $config = $this->job->configuration;
     $content = $this->job->uploadFileContents();
     // create CSV reader.
     $reader = Reader::createFromString($content);
     $reader->setDelimiter($config['delimiter']);
     $start = $config['has-headers'] ? 1 : 0;
     $results = $reader->fetch();
     Log::notice('Building importable objects from CSV file.');
     foreach ($results as $index => $row) {
         if ($index >= $start) {
             $line = $index + 1;
             Log::debug('----- import entry build start --');
             Log::debug(sprintf('Now going to import row %d.', $index));
             $importEntry = $this->importSingleRow($index, $row);
             $this->collection->put($line, $importEntry);
             /**
              * 1. Build import entry.
              * 2. Validate import entry.
              * 3. Store journal.
              * 4. Run rules.
              */
             $this->job->addTotalSteps(4);
             $this->job->addStepsDone(1);
         }
     }
     Log::debug(sprintf('Import collection contains %d entries', $this->collection->count()));
     Log::notice(sprintf('Built %d importable object(s) from your CSV file.', $this->collection->count()));
     return $this->collection;
 }
Example #4
0
 public static function move(Collection &$cards, $num = 1, $from = false, $to = false)
 {
     if ($num === 0) {
         return;
     }
     if ($num === static::ALL) {
         $num = $cards->get($from)->count();
     }
     //sets the defaults
     if (!$from) {
         $from = static::DRAW;
     }
     if (!$to) {
         $to = static::DISCARD;
     }
     //check indexs exist
     if (!$cards->get($from) instanceof Collection) {
         $cards->put($from, collect([]));
     }
     if (!$cards->get($to) instanceof Collection) {
         $cards->put($to, collect([]));
     }
     $discarded = $cards->get($from)->splice(0, $num);
     $cards->get($to)->splice($cards->get($to)->count(), 0, $discarded->all());
     return;
 }
Example #5
0
 /**
  * Modules of installed or not installed.
  *
  * @param bool $installed
  *
  * @return \Illuminate\Support\Collection
  */
 public function getModules($installed = false)
 {
     if ($this->modules->isEmpty()) {
         if ($this->files->isDirectory($this->getModulePath()) && !empty($directories = $this->files->directories($this->getModulePath()))) {
             (new Collection($directories))->each(function ($directory) use($installed) {
                 if ($this->files->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) {
                     $package = new Collection(json_decode($this->files->get($file), true));
                     if (Arr::get($package, 'type') == 'notadd-module' && ($name = Arr::get($package, 'name'))) {
                         $module = new Module($name);
                         $module->setAuthor(Arr::get($package, 'authors'));
                         $module->setDescription(Arr::get($package, 'description'));
                         if ($installed) {
                             $module->setInstalled($installed);
                         }
                         if ($entries = data_get($package, 'autoload.psr-4')) {
                             foreach ($entries as $namespace => $entry) {
                                 $module->setEntry($namespace . 'ModuleServiceProvider');
                             }
                         }
                         $this->modules->put($directory, $module);
                     }
                 }
             });
         }
     }
     return $this->modules;
 }
 /**
  * @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);
 }
 /**
  * @param \KodiCMS\Widgets\Contracts\WidgetType $type
  *
  * @return $this
  */
 public function registerWidget(\KodiCMS\Widgets\Contracts\WidgetType $type)
 {
     if (!$this->isCorrupt($type->getClass())) {
         $this->types->put($type->getType(), $type);
     }
     return $this;
 }
Example #8
0
 /**
  * @param $key
  * @param $value
  * @throws \Exception
  */
 public function register($key, $value)
 {
     if ($value instanceof Theme) {
         $this->list->put($key, $value);
     } else {
         throw new Exception('正在注册未知类型的主题!');
     }
 }
Example #9
0
 /**
  * @return \Illuminate\Support\Collection
  */
 public function getData()
 {
     $data = new Collection();
     $data->put('title', $this->title);
     $data->put('description', $this->description);
     $data->put('keywords', $this->keywords);
     return $data;
 }
Example #10
0
 /**
  * Update a Satis repository.
  *
  * @param  \KevinDierkx\Muse\Repositories\Satis\RepositoryInterface  $model
  * @param  array                                                     $data
  * @return \KevinDierkx\Muse\Repositories\Satis\RepositoryInterface
  */
 public function update(RepositoryInterface $model, array $data)
 {
     // TODO: Fire updating event
     $model->fill($data);
     $this->repositories->put($model->getId(), $model);
     $this->flush();
     // TODO: Fire updated event
     return $model;
 }
Example #11
0
 /**
  * Appends the given resources to the ones already being used
  * @param array $resources
  */
 public function addResources(array $resources)
 {
     if (!$this->resources instanceof Collection) {
         $this->resources = new Collection();
     }
     foreach ($resources as $resource => $class) {
         $this->resources->put($resource, ['instance' => null, 'class' => $class]);
     }
 }
Example #12
0
 public function install(\Illuminate\Http\Request $request)
 {
     if (file_exists("../.env")) {
         flash()->overlay(".env file already exists, can't overwrite", "Whoops!");
         return redirect('/');
     }
     $envstrings = new Collection();
     $adminuser = new Collection();
     //Make sure all necessary values were submitted
     $this->validate($request, ['db_driver' => 'required|in:mysql,pgsql,sqlsrv,sqlite', 'db_host' => 'required_if:db_driver,mysql,pgsql,sqlsrv', 'db_database' => 'required_if:db_driver,mysql,pgsql,sqlsrv|alpha_dash', 'db_username' => 'required_if:db_driver,mysql,pgsql,sqlsrv', 'db_password' => 'required_if:db_driver,mysql,pgsql,sqlsrv', 'db_prefix' => 'required|alpha_dash', 'user_username' => 'required|alpha_dash', 'user_email' => 'required|email', 'user_password' => 'required|same:user_confirmpassword', 'user_confirmpassword' => 'required', 'user_realname' => 'required', 'user_language' => 'required', 'mail_host' => 'required', 'mail_from_address' => 'required|email', 'mail_from_name' => 'required', 'mail_username' => 'required', 'mail_password' => 'required', 'recaptcha_public_key' => 'required', 'recaptcha_private_key' => 'required', 'baseurl_url' => 'required', 'basepath' => 'required']);
     $envstrings->put("db_driver", $request->input("db_driver"));
     $envstrings->put("db_host", $request->input("db_host"));
     $envstrings->put("db_database", $request->input("db_database"));
     $envstrings->put("db_username", $request->input("db_username"));
     $envstrings->put("db_password", $request->input("db_password"));
     $envstrings->put("db_prefix", $request->input("db_prefix"));
     $envstrings->put("mail_host", $request->input("mail_host"));
     $envstrings->put("mail_from_address", $request->input("mail_from_address"));
     $envstrings->put("mail_from_name", $request->input("mail_from_name"));
     $envstrings->put("mail_username", $request->input("mail_username"));
     $envstrings->put("mail_password", $request->input("mail_password"));
     $envstrings->put("recaptcha_public_key", $request->input("recaptcha_public_key"));
     $envstrings->put("recaptcha_private_key", $request->input("recaptcha_private_key"));
     $envstrings->put("baseurl_url", $request->input("baseurl_url"));
     $envstrings->put("basepath", $request->input("basepath"));
     $adminuser->put('user_username', $request->input("user_username"));
     $adminuser->put('user_email', $request->input("user_email"));
     $adminuser->put('user_password', $request->input('user_password'));
     $adminuser->put('user_realname', $request->input('user_realname'));
     $adminuser->put('user_language', $request->input('user_language'));
     try {
         $dbtype = $envstrings->get('db_driver');
         if ($dbtype == "mysql") {
             $dbc = new \PDO('mysql:host=' . $envstrings->get("db_host") . ';dbname=' . $envstrings->get("db_database"), $envstrings->get('db_username'), $envstrings->get('db_password'));
         } elseif ($dbtype == "pgsql") {
             $dbc = new \PDO('pgsql:host=' . $envstrings->get("db_host") . ';dbname=' . $envstrings->get("db_database"), $envstrings->get('db_username'), $envstrings->get('db_password'));
         } elseif ($dbtype == "sqlsrv") {
             $dbc = new \PDO('pgsql:Server=' . $envstrings->get("db_host") . ';Databasee=' . $envstrings->get("db_database"), $envstrings->get('db_username'), $envstrings->get('db_password'));
         }
     } catch (\PDOException $e) {
         flash()->overlay("Can't connect to the database with the information provided", "Whoops!");
         return redirect()->back()->withInput();
     } finally {
         $dbc = null;
         //required to close PDO connection
     }
     $status = $this->writeEnv($envstrings);
     if ($status == true) {
         $request->session()->put("adminuser", $adminuser);
         //Pass user data to next method
         return redirect('/install/migrate');
     } else {
         flash()->overlay("Your settings couldn't be saved. Make sure that PHP has permission to save the .env file", "Whoops!");
         return redirect()->back()->withInput();
     }
 }
Example #13
0
 /**
  * Plant a new bonsai collection!
  *
  * @param  string  $namespace
  * @param  string  $path
  * @return null
  */
 public function plant($callback = null)
 {
     $assets = new Assets();
     if (is_callable($callback)) {
         call_user_func($callback, $assets);
     }
     $this->collection->put('bonsai', $assets);
     $this->view->share('bonsai', $assets);
     return $assets;
 }
Example #14
0
 /**
  * Handles the creation of a menu, or returns it if it exists
  *
  * @param  string       $menuName
  * @param  string 		$menuText
  * @param  array 		$attributes
  * @return Stillat\Menu
  */
 public function handle($menuName, $menuText, array $attributes = array())
 {
     if ($this->hasMenu($menuName) == false) {
         $attributes['text'] = $menuText;
         $menu = new Menu($menuName, $attributes);
         $menu->setRenderer($this->renderer);
         $this->menuCollection->put($menuName, $menu);
     }
     return $this->getMenu($menuName);
 }
Example #15
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 #16
0
 /**
  * Creates a new menu or returns an existing
  *
  * @param string $id
  *
  * @return \Codex\Core\Menus\Menu
  */
 public function add($id)
 {
     if ($this->has($id)) {
         return $this->get($id);
     }
     $menu = $this->getContainer()->make('codex.builder.menu', ['menuFactory' => $this, 'id' => $id]);
     $this->runHook('menu-factory:add', [$this, $menu]);
     $this->menus->put($id, $menu);
     return $menu;
 }
Example #17
0
 public function runCriteria()
 {
     foreach ($this->criteria()->all() as $key => $criteria) {
         if (is_string($criteria) && is_subclass_of($criteria, BaseCriteria::class)) {
             $this->criteria->put($key, $criteria = app($criteria));
         }
         if ($criteria instanceof BaseCriteria) {
             $criteria->apply($this);
         }
     }
 }
Example #18
0
 /**
  * Build the menu structure.
  *
  * @return mixed
  */
 public function getItemProviders()
 {
     foreach ($this->modules->enabled() as $module) {
         $name = studly_case($module->getName());
         $class = 'Modules\\' . $name . '\\MenuExtenders\\MenuExtender';
         if (class_exists($class)) {
             $extender = $this->container->make($class);
             $this->extenders->put($module->getName(), ['content' => $extender->getContentItems(), 'static' => $extender->getStaticItems()]);
         }
     }
     return $this->extenders;
 }
Example #19
0
 /**
  * Add a CSS dependency on the view
  * @param string $dependency
  * @return $this
  * @throws AssetNotFoundException
  */
 public function requireCss($dependency)
 {
     if (is_array($dependency)) {
         foreach ($dependency as $dependency) {
             $this->requireCss($dependency);
         }
     }
     $assetPath = $this->assetManager->getCss($dependency);
     $this->guardForAssetNotFound($assetPath);
     $this->css->put($dependency, $assetPath);
     return $this;
 }
Example #20
0
 public function show($year, $month, $day)
 {
     $date = $this->createDate($year, $month, $day);
     $photos = new Collection();
     $photo = new Photo($date);
     if ($photo->exists() === false) {
         return $this->redirectToNewestPhoto();
     }
     $photos->put('prev', $photo->findPrevPhoto());
     $photos->put('curr', $photo);
     $photos->put('next', $photo->findNextPhoto());
     return response()->json($photos);
 }
Example #21
0
 /**
  * @param OfferComponent $component
  *
  * @return bool
  */
 public function takeComponent(OfferComponent $component) : bool
 {
     // Don't accept if this offer does not apply to the product.
     if (!$this->appliesToProduct($component->product())) {
         return false;
     }
     // Don't accept if this offer is already fulfilled.
     if ($this->requirementsAreMet()) {
         return false;
     }
     $this->components->put($component->id(), $component);
     return true;
 }
Example #22
0
 /**
  * Create a new menu instance
  *
  * @param  string  $name
  * @param  callable  $callback
  * @return \Lavary\Menu\Menu
  */
 public function make($name, $callback)
 {
     if (is_callable($callback)) {
         $menu = new Builder();
         // Registering the items
         call_user_func($callback, $menu);
         // Storing each menu instance in the collection
         $this->collection->put($name, $menu);
         // Make the instance available in all views
         \View::share($name, $menu);
         return $menu;
     }
 }
Example #23
0
 /**
  * @param Record $record
  * @param null $keyed_by
  */
 public function addRecord(Record $record, $keyed_by = null)
 {
     // register this Results object as the record's parent automatically
     $record->setParent($this);
     $this->returned_results_count++;
     if (is_callable($keyed_by)) {
         $this->results->put($keyed_by($record), $record);
     } elseif ($keyed_by) {
         $this->results->put($record->get($keyed_by), $record);
     } else {
         $this->results->push($record);
     }
 }
Example #24
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;
 }
Example #25
0
 public function __construct($presenter, Collection $collection)
 {
     foreach ($collection as $key => $resource) {
         $collection->put($key, new $presenter($resource));
     }
     $this->items = $collection->toArray();
 }
Example #26
0
 /**
  * Add a Hydrator to the collection
  *
  * @param  string                                   $type
  * @param  \rsanchez\Deep\Hydrator\AbstractHydrator $hydrator
  * @return void
  */
 public function put($type, $hydrator)
 {
     if (!$hydrator instanceof AbstractHydrator) {
         throw new \Exception('$hydrator must be instance of \\rsanchez\\Deep\\Hydrator\\AbstractHydrator');
     }
     return parent::put($type, $hydrator);
 }
Example #27
0
 /**
  * @return Collection
  */
 public function getExtensions()
 {
     $extensionsDir = $this->getExtensionsDir();
     $dirs = array_diff(scandir($extensionsDir), ['.', '..']);
     $extensions = new Collection();
     $installed = json_decode(file_get_contents(public_path('vendor/composer/installed.json')), true);
     foreach ($dirs as $dir) {
         if (file_exists($manifest = $extensionsDir . '/' . $dir . '/composer.json')) {
             $extension = new Extension($extensionsDir . '/' . $dir, json_decode(file_get_contents($manifest), true));
             if (empty($extension->name)) {
                 continue;
             }
             foreach ($installed as $package) {
                 if ($package['name'] === $extension->name) {
                     $extension->setInstalled(true);
                     $extension->setVersion($package['version']);
                     $extension->setEnabled($this->isEnabled($dir));
                 }
             }
             $extensions->put($dir, $extension);
         }
     }
     return $extensions->sortBy(function ($extension, $name) {
         return $extension->composerJsonAttribute('extra.flarum-extension.title');
     });
 }
 /**
  * resolves all existing plans
  *
  * @param array $config
  */
 private function resolvePlans(array $config)
 {
     foreach ($config as $id => $planData) {
         $plan = Plan::createFromArray($id, $planData);
         $this->plans->put($id, $plan);
     }
 }
Example #29
0
 /**
  * Extension list.
  *
  * @return \Illuminate\Support\Collection
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  */
 public function getExtensions()
 {
     if ($this->extensions->isEmpty()) {
         if ($this->files->isDirectory($this->getExtensionPath()) && !empty($vendors = $this->files->directories($this->getExtensionPath()))) {
             collect($vendors)->each(function ($vendor) {
                 if ($this->files->isDirectory($vendor) && !empty($directories = $this->files->directories($vendor))) {
                     collect($directories)->each(function ($directory) {
                         if ($this->files->exists($file = $directory . DIRECTORY_SEPARATOR . 'composer.json')) {
                             $package = new Collection(json_decode($this->files->get($file), true));
                             if (Arr::get($package, 'type') == 'notadd-extension' && ($name = Arr::get($package, 'name'))) {
                                 $extension = new Extension($name);
                                 $extension->setAuthor(Arr::get($package, 'authors'));
                                 $extension->setDescription(Arr::get($package, 'description'));
                                 if ($entries = data_get($package, 'autoload.psr-4')) {
                                     foreach ($entries as $namespace => $entry) {
                                         $extension->setEntry($namespace . 'Extension');
                                     }
                                 }
                                 $this->extensions->put($directory, $extension);
                             }
                         }
                     });
                 }
             });
         }
     }
     return $this->extensions;
 }
 /**
  * Put an item in the collection by key.
  *
  * @param  mixed  $key
  * @param  mixed  $value
  * @return $this
  */
 public function put($key, $value)
 {
     if (!$value instanceof Repository) {
         throw new InvalidArgumentException('RepositoryCollection accepts only elements of "Repository" type.');
     }
     return parent::put($key, $value);
 }