/** * Processes logging in a user. * * @param LoginRequest $request * * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse */ public function authenticate(LoginRequest $request) { try { $input = $request->all(); $remember = (bool) array_pull($input, 'remember', false); if ($auth = Sentinel::authenticate($input, $remember)) { $message = 'Successfully logged in.'; return redirect()->intended(route('maintenance.dashboard.index'))->withSuccess($message); } else { if (Corp::auth($input['login'], $input['password'])) { $user = Corp::user($input['login']); $name = explode(',', $user->name); $credentials = ['email' => $user->email, 'username' => $user->username, 'password' => $input['password'], 'first_name' => array_key_exists(1, $name) ? $name[1] : null, 'last_name' => array_key_exists(0, $name) ? $name[0] : null]; return $this->registerAndAuthenticateUser($credentials); } } $errors = 'Invalid login or password.'; } catch (NotActivatedException $e) { $errors = 'Account is not activated!'; } catch (ThrottlingException $e) { $delay = $e->getDelay(); $errors = "Your account is blocked for {$delay} second(s)."; } return redirect()->back()->withErrors($errors); }
function testArrayPull2dAssoc() { $arr = array('a' => array('i' => 1, 'ii' => 2), 'b' => array('iii' => 3, 'iv' => 4), 'c' => array('v' => 5, 'vi' => 6)); $pull = array('a', 'c'); $new = array_pull($arr, $pull); $this->assertEquals($new, array('a' => array('i' => 1, 'ii' => 2), 'c' => array('v' => 5, 'vi' => 6))); }
/** * Make a field type. * * @param array $parameters * @param StreamInterface $stream * @param null $entry * @return FieldType */ public function make(array $parameters, StreamInterface $stream = null, $entry = null) { /* @var EntryInterface $entry */ if ($stream && $entry instanceof EntryInterface && $entry->hasField(array_get($parameters, 'field'))) { $field = clone $entry->getFieldType(array_get($parameters, 'field')); $modifier = $field->getModifier(); $value = array_pull($parameters, 'value'); /* @var EntryInterface $entry */ $field->setValue(!is_null($value) ? $modifier->restore($value) : $entry->getAttribute($field->getField())); } elseif (is_object($entry)) { $field = $this->builder->build($parameters); $modifier = $field->getModifier(); $value = array_pull($parameters, 'value'); $field->setValue(!is_null($value) ? $modifier->restore($value) : $entry->{$field->getField()}); } else { $field = $this->builder->build($parameters); $modifier = $field->getModifier(); $field->setValue($modifier->restore(array_pull($parameters, 'value'))); } // Set the entry. $field->setEntry($entry); // Merge in rules and validators. $field->mergeRules(array_pull($parameters, 'rules', []))->mergeConfig(array_pull($parameters, 'config', []))->mergeMessages(array_pull($parameters, 'messages', []))->mergeValidators(array_pull($parameters, 'validators', [])); // Hydrate the field with parameters. $this->hydrator->hydrate($field, $parameters); return $field; }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $this->validate($request, ['penerima' => 'required']); $all = $request->all(); // dd($all); $pengadaanFill = $this->pengadaanBarang->getFillable(); $pengadaan = $this->pengadaanBarang->Create($request->only($pengadaanFill)); // dd($all); try { foreach ($all['barpeng'] as $barpeng) { if (!is_numeric($barpeng['kuantitas'])) { return redirect()->back()->withErrors(['Kuantitas harus berupa angka']); } else { $addedItem = Barang::find($barpeng['barang_id']); $addedItem['pengadaan'] += $barpeng['kuantitas']; $addedItem->save(); // dd($addedItem); Barang::find($barpeng['barang_id'])->update($addedItem->toArray()); $barang_id = array_pull($barpeng, 'barang_id'); $pengadaan->barangs()->attach($barang_id, $barpeng); } } return redirect('pengadaan/index'); } catch (Exception $e) { return redirect()->back()->withErrors($e); } }
/** * Sprintf and execute a command * * @param string $message * @param string $parameters ... * * @return void */ protected function execf() { $arguments = func_get_args(); $message = array_pull($arguments, 0); $command = vsprintf($message, $arguments); return exec($command); }
/** * @param array $options */ public function __construct(array $options = []) { parent::__construct(['di' => $this->buildDi((array) array_pull($options, 'di'))]); $this->registerInstance($this); $this->validate($options); $this->registerConfig($options); }
/** * Route a model to an api controller. * * @param string $model * @param array $options * @return void */ public function apiResource($model, array $options = array()) { $parent = array_pull($options, 'parent', false); $name = array_pull($options, 'name', false); $controller = array_pull($options, 'controller', $this->controller); if (!$name) { // nest resource routes if parent is present if ($parent) { // conventionally we should avoid being repetitive // nested model routes should not reference parents if (strpos($model, $parent) === 0) { $model = substr($model, strlen($parent)); } $model = static::prepareEntityBaseName($model); $parent = static::prepareEntityBaseName($parent); $only = array_pull($options, 'only', false); $except = array_pull($options, 'except', []); $addIndexAction = (false === $only || in_array('index', $only)) && !in_array('index', $except); // special case resource index method needs to be handled separately here if ($addIndexAction) { $name = $parent . '.' . $model; $this->addResourceIndex($name, $model, $controller, $options); // make sure we skip the index action when we call the resource method $options['except'] = array_merge($except, ['index']); } // set prefixed name for all other resource actions $name = $parent . '/{' . $parent . '}/' . $model; } else { $model = static::prepareEntityBaseName($model); $name = $model; } } // hand off to default resource router $this->resource($name, $controller, $options); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(\Illuminate\Http\Request $request) { // Sanity: Make sure $request is valid if (!$request->has('Profile')) { return response('{"Error": "Invalid Request"}', 422); } else { $this->validate($request, ['Profile' => 'required|json']); } // Sanitize the request and extract an assoc array $data = json_decode($request->input('Profile'), true); $validate = Validator::make($data, ['profile_name' => 'required|alpha_num', "number" => 'required', "numbers" => 'required', "lower" => 'required', "lower_case" => 'required', "upper" => 'required', "upper_case" => 'required', "symbol" => 'required', "symbols" => 'required', "special" => 'required', "specials" => 'required', "length" => 'required', "count" => 'required', "entropy" => 'required']); if ($validate->fails()) { return response('{"Error": "Invalid Request"}', 422); } // Sanity Check: (model exist) ? 'update it' : 'create it' // Pull 'profile_name' from $data array $model = PassProfile::firstOrNew(['profile_name' => array_pull($data, 'profile_name')]); // Fill $model foreach ($data as $key => $value) { $model[$key] = $value; } // Save model $model->save(); return $model->toJson(); }
/** * Normalize the assignments input. * * @param Migration $migration */ public function normalize(Migration $migration) { $locale = $this->config->get('app.fallback_locale'); $stream = $migration->getStream(); $assignments = $migration->getAssignments(); foreach ($assignments as $field => &$assignment) { /* * If the assignment is a simple string * then the assignment is the field slug. */ if (is_string($assignment)) { $assignment = ['field' => $assignment]; } /* * Generally the field will be the * array key. Make sure we have one. */ if (!isset($assignment['field'])) { $assignment['field'] = $field; } /* * If any of the translatable items exist * in the base array then move them up into * the translation array. */ foreach (['label', 'warning', 'instructions', 'placeholder'] as $key) { if ($value = array_pull($assignment, $key)) { $assignment = array_add($assignment, $locale . '.' . $key, $value); } } } $migration->setAssignments($assignments); }
protected function clientUpdate($params) { //wrap body params with "doc" to fit update api $body = array_pull($params, 'body'); $params['body']['doc'] = $body; return $this->es_client->update($params); }
/** * Normalize the fields input. * * @param Migration $migration */ public function normalize(Migration $migration) { $locale = $this->config->get('app.fallback_locale'); $fields = $migration->getFields(); foreach ($fields as $slug => &$field) { /* * If the field is a simple string then * the $slug is used as is and the field * must be the field type. */ if (is_string($field)) { $field = ['type' => $field]; } if (!isset($field['type'])) { throw new \Exception("The [type] parameter must be defined in fields."); } $field['slug'] = array_get($field, 'slug', $slug); $field['namespace'] = array_get($field, 'namespace', $migration->contextualNamespace()); /* * If any of the translatable items exist * in the base array then move them up into * the translation array. */ foreach (['name', 'instructions', 'placeholder', 'warning'] as $key) { if ($value = array_pull($field, $key)) { $field = array_add($field, $locale . '.' . $key, $value); } } } $migration->setFields($fields); }
/** * Boot service, registering providers. * * @return void */ public function boot() { foreach ($this->toBoot as $key => $class) { array_pull($this->toBoot, $key); $this->registerProvider($class); } }
/** * Constructor. * * @param array $config */ public function __construct(array $config) { // Setup cache groups $cacheGroups = array_pull($config, 'groups'); $this->setupCacheGroups($cacheGroups); // Set cache config $this->config = $config; }
/** * @param ImageManager $imageManager * @param Container $container * @param array $config */ protected function configureManager(ImageManager $imageManager, Container $container, array $config) { $adapterConfigs = array_merge(array_get($config, 'adapters', []), self::$defaultAdapters); foreach ($adapterConfigs as $adapterConfig) { $className = array_pull($adapterConfig, 'class'); $adapter = $container->make($className, ['config' => $adapterConfig]); $imageManager->addAdapter($adapter); } }
/** * Normalize button input. * * @param TreeBuilder $builder */ public function normalize(TreeBuilder $builder) { $buttons = $builder->getButtons(); foreach ($buttons as $key => &$button) { /* * If the button is a string then use * it as the button parameter. */ if (is_string($button)) { $button = ['button' => $button]; } /* * If the key is a string and the button * is an array without a button param then * move the key into the button as that param. */ if (!is_integer($key) && !isset($button['button'])) { $button['button'] = $key; } /* * Make sure some default parameters exist. */ $button['attributes'] = array_get($button, 'attributes', []); /* * Move the HREF if any to the attributes. */ if (isset($button['href'])) { array_set($button['attributes'], 'href', array_pull($button, 'href')); } /* * Move the target if any to the attributes. */ if (isset($button['target'])) { array_set($button['attributes'], 'target', array_pull($button, 'target')); } /* * Move all data-* keys * to attributes. */ foreach ($button as $attribute => $value) { if (str_is('data-*', $attribute)) { array_set($button, 'attributes.' . $attribute, array_pull($button, $attribute)); } } /* * Make sure the HREF is absolute. */ if (isset($button['attributes']['href']) && is_string($button['attributes']['href']) && !starts_with($button['attributes']['href'], 'http')) { $button['attributes']['href'] = url($button['attributes']['href']); } /* * Use small buttons for trees. */ $button['size'] = array_get($button, 'size', 'xs'); } $builder->setButtons($buttons); }
/** * Create a new Redis connection instance. * * @param array $servers * @return void */ public function __construct(array $servers = []) { $cluster = array_pull($servers, 'cluster'); $options = (array) array_pull($servers, 'options'); if ($cluster) { $this->clients = $this->createAggregateClient($servers, $options); } else { $this->clients = $this->createSingleClients($servers, $options); } }
/** * Fill attributes and save locales if exists . * * @param array $attributes * @return mixed */ public function fill(array $attributes) { $locales = Locale\get_locales(); foreach ($locales as $locale => $options) { if (in_array($locale, array_keys($attributes))) { $this->translations[$locale] = array_pull($attributes, $locale); } } return parent::fill($attributes); }
protected function process($key, $button) { /** * If the button is a string then use * it as the button parameter. */ if (is_string($button)) { $button = ['button' => $button]; } /** * If the key is a string and the button * is an array without a button param then * move the key into the button as that param. */ if (!is_integer($key) && !isset($button['button'])) { $button['button'] = $key; } /** * Make sure some default parameters exist. */ $button['attributes'] = array_get($button, 'attributes', []); /** * Move the HREF if any to the attributes. */ if (isset($button['href'])) { array_set($button['attributes'], 'href', array_pull($button, 'href')); } /** * Move the target if any to the attributes. */ if (isset($button['target'])) { array_set($button['attributes'], 'target', array_pull($button, 'target')); } /** * Move all data-* keys * to attributes. */ foreach ($button as $attribute => $value) { if (str_is('data-*', $attribute)) { array_set($button, 'attributes.' . $attribute, array_pull($button, $attribute)); } } /** * Make sure the HREF is absolute. */ if (isset($button['attributes']['href']) && is_string($button['attributes']['href']) && !starts_with($button['attributes']['href'], 'http')) { $button['attributes']['href'] = url($button['attributes']['href']); } if (isset($button['dropdown'])) { foreach ($button['dropdown'] as $key => &$dropdown) { $dropdown = $this->process($key, $dropdown); } } return $button; }
/** * Run the command. */ public function run() { $data = $this->dispatch(new ReadEnvironmentFile()); if ($timezone = array_pull($data, 'APP_TIMEZONE')) { $this->settings->create(['key' => 'streams::timezone', 'value' => $timezone]); } if ($locale = array_pull($data, 'DEFAULT_LOCALE')) { $this->settings->create(['key' => 'streams::default_locale', 'value' => $locale]); } $this->dispatch(new WriteEnvironmentFile($data)); }
public static function parseDSN(array $params) { $driver = array_pull($params, 'driver'); $database = array_pull($params, 'database'); $params = array_merge(['dbname' => $database], array_except($params, ['username', 'password', 'collation', 'prefix', 'strict'])); $data = []; foreach ($params as $key => $value) { $data[] = $key . '=' . $value; } return $driver . ':' . implode(';', $data); }
/** * Assign high numeric IDs to a config item to force appending. * * @param array $array * @return array */ function append_config(array $array) { $start = 9999; foreach ($array as $key => $value) { if (is_numeric($key)) { $start++; $array[$start] = array_pull($array, $key); } } return $array; }
protected function pullParent(array $fields) { if (empty($this->config['setup']['mapping']['parent'])) { return [$fields, null]; } if (empty($fields['_parent_id'])) { throw new \InvalidArgumentException('parent required'); } $parent = array_pull($fields, '_parent_id'); return [$fields, $parent]; }
/** * Updates a metric point. * * @param \CachetHQ\Cachet\Models\Metric $metric * @param \CachetHQ\Cachet\Models\MetircPoint $metricPoint * * @return \Illuminate\Http\JsonResponse */ public function putMetricPoint(Metric $metric, MetricPoint $metricPoint) { $metricPointData = Binput::all(); $metricPointData['metric_id'] = $metric->id; if ($timestamp = array_pull($metricPointData, 'timestamp')) { $pointTimestamp = Carbon::createFromFormat('U', $timestamp); $metricPointData['created_at'] = $pointTimestamp->format('Y-m-d H:i:s'); } $metricPoint->update($metricPointData); return $this->item($metricPoint); }
/** * Prepare widget variables */ public function prepareVars() { $leftConfig = $this->getConfig('left'); $rightConfig = $this->getConfig('right'); $this->vars['leftLabel'] = array_pull($leftConfig, 'label', ''); $this->vars['rightLabel'] = array_pull($rightConfig, 'label', ''); $loadValue = $this->getLoadValue(); $this->vars['selected'] = $this->jsonable && is_array($loadValue) && isset($loadValue['side']) ? $loadValue['side'] : self::LEFT; $this->vars[self::LEFT] = $this->makeNestedFormWidget(self::LEFT, $leftConfig); $this->vars[self::RIGHT] = $this->makeNestedFormWidget(self::RIGHT, $rightConfig); }
protected function clientUpdate($params) { try { //wrap body params with "doc" to fit update api $body = array_pull($params, 'body'); $params['body']['doc'] = $body; $response = $this->es_client->update($params); } catch (\Exception $e) { return ['error' => get_class($e)]; } return $response; }
/** * @param $data * * @return mixed */ public function add($data) { // authenticated user $authUser = auth()->user(); $productID = array_pull($data, 'product_id'); // associate the review to a product and the currently logged in user $this->model->creating(function ($r) use($productID, $authUser) { $r->product_id = $productID; $r->user_id = $authUser->getAuthIdentifier(); }); return parent::add($data); }
/** * Return a matcher for a field * * @param array $attributes * * @return array */ protected function matchField($attributes = array()) { $tag = array_pull($attributes, 'tag') ?: 'input'; $children = array_pull($attributes, 'children'); // Create attributes array $attributes = array_merge(array('name' => 'dummy', 'type' => 'text'), $attributes); // Remove type if not an input if ($tag !== 'input') { unset($attributes['type']); } return array('tag' => $tag, 'id' => $attributes['name'], 'attributes' => $attributes, 'children' => $children); }
public function store(Request $request) { $keys = 'title,content,bid,cover_aids,shop_rate,agent_rate,express_price,keywords,description,activity_type'; $data = $this->autoValidate($request, 'product.store', $keys); $cover_aids = array_pull($data, 'cover_aids'); $data += ['fid' => $this->factory->getKey()]; $product = Product::create($data); foreach ($cover_aids as $value) { $product->covers()->create(['cover_aid' => $value]); } return $this->success('', url('factory/product')); }
/** * Guess the field unique rule. * * @param FormBuilder $builder */ public function guess(FormBuilder $builder) { $fields = $builder->getFields(); $entry = $builder->getFormEntry(); foreach ($fields as &$field) { $unique = array_pull($field, 'rules.unique'); /* * No unique? Continue... */ if (!$unique || $unique === false) { continue; } /* * If unique is a string then * it's set explicitly. */ if ($unique && is_string($unique)) { $field['rules']['unique'] = 'unique:' . $unique; continue; } /* * If unique is true then * automate the rule. */ if ($unique && $unique === true) { $unique = 'unique:' . $entry->getTable() . ',' . $field['field']; if ($entry instanceof EntryInterface) { $unique .= ',' . $entry->getId(); } $field['rules']['unique'] = $unique; continue; } /* * If unique is an array then use * the default automation and add to it. */ if ($unique && is_array($unique)) { $unique = 'unique:' . $entry->getTable() . ',' . $field['field']; if ($entry instanceof EntryInterface) { $unique .= ',' . $entry->getId(); } $keys = array_keys($unique); $values = array_values($unique); foreach ($keys as $column) { $unique .= ',' . $column . ',' . $column . ',' . array_shift($values); } $field['rules']['unique'] = $unique; continue; } } $builder->setFields($fields); }
/** * {@inheritdoc} */ protected function getView(Request $request) { $view = parent::getView($request); $queryParams = $request->getQueryParams(); $sort = array_pull($queryParams, 'sort'); $q = array_pull($queryParams, 'q'); $page = array_pull($queryParams, 'page', 1); $params = ['sort' => $sort && isset($this->sortMap[$sort]) ? $this->sortMap[$sort] : '', 'filter' => compact('q'), 'page' => ['offset' => ($page - 1) * 20, 'limit' => 20]]; $document = $this->getDocument($request->getAttribute('actor'), $params); $view->setDocument($document); $view->setContent(app('view')->make('flarum.forum::index', compact('document', 'page', 'forum'))); return $view; }