/** * Execute the console command. * * @return mixed */ public function fire() { $filename = $this->argument('filename'); $stream = fopen($filename, 'r'); $this->user = User::whereEmail('*****@*****.**')->first(); try { $listener = new StreamingJsonListener(function ($entry) { $name = $this->clean($entry['author']); if (array_has($this->ignore, strtolower($name)) || str_contains(strtolower($name), 'quote')) { $quote = $this->clean($entry['text']); $this->output->write("{$this->count}: {$name} "); $this->error("{$quote}"); } else { $author = Author::firstOrCreate(['name' => $name]); if (!array_has($this->authors, strtolower($name))) { $this->authors[strtolower($name)] = true; } $quote = $this->clean($entry['text']); $q = new Quote(['content' => $quote, 'user_id' => $this->user->id, 'author_id' => $author->id, 'published' => true]); if ($q->save()) { $this->count++; $this->output->writeln("{$this->count}: {$name} <info>{$quote}</info>"); } else { $this->output->write("{$this->count}: {$name} "); $this->warn("{$quote}"); } } }); $parser = new \JsonStreamingParser_Parser($stream, $listener); $parser->parse(); $this->info("{$this->count} quotes pushed."); } catch (\JsonStreamingParser_ParsingError $e) { fclose($stream); } }
protected function with($data) { if (!is_object($this->entity)) { return $this; } $func_name = array_get($data, 'func_name'); $classFullName = starts_with($func_name, "\\") ? $func_name : "\\Veer\\Components\\Ecommerce\\" . $func_name; if (!empty($func_name) && !class_exists($classFullName)) { event('veer.message.center', trans('veeradmin.shipping.error')); return $this; } $data['discount_price'] = strtr(array_get($data, 'discount_price'), ["%" => ""]); $data['enable'] = isset($data['enable']) ? true : false; $data['discount_enable'] = isset($data['discount_enable']) ? true : false; if (array_has($data, 'address')) { $addresses = preg_split('/[\\n\\r]+/', array_get($data, 'address')); // @todo redo foreach ($addresses as $k => $address) { $parts = explode("|", $address); $parts = array_filter($parts, function ($value) { if (!empty($value)) { return $value; } }); $addresses[$k] = $parts; } $data['address'] = json_encode($addresses); } $this->entity->fill($data); $this->entity->save(); return $this; }
public function __construct($options = []) { if (!array_has($options, 'redirectUri')) { $options['redirectUri'] = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING']; } parent::__construct($options); }
/** * The pages short content * * @return mixed null|string */ public function getExcerptAttribute() { if (array_has($this->attributes, 'body')) { return str_limit(strip_tags($this->attributes['body']), 200); } return null; }
/** * A basic test example. * * @return void */ public function testSamplingCreationWithPost() { $product = App\Product::with('sensors')->get()->random(); $generic_sensors = App\GenericSensor::all(); $generic_sensor_with_random_function = array(); foreach ($generic_sensors as $generic_sensor) { // Humidity, Pressure, Temperature switch ($generic_sensor->alias) { case "Humidity": $generic_sensor_with_random_function[$generic_sensor->getKey()] = 'getRandomHumidityValue'; break; case "Temperature": $generic_sensor_with_random_function[$generic_sensor->getKey()] = 'getRandomTemperatureValue'; break; case "Pressure": $generic_sensor_with_random_function[$generic_sensor->getKey()] = 'getRandomPressureValue'; break; } } $newSamplings = array(); foreach ($product->sensors as $sensor) { $gs_id = $sensor->generic_sensor_id; if (!array_has($generic_sensor_with_random_function, $gs_id)) { continue; } $sensor_random_value = call_user_func(array($this, $generic_sensor_with_random_function[$gs_id])); array_push($newSamplings, array('generic_sensor_id' => $gs_id, 'value' => $sensor_random_value)); } $request_body = array('product_id' => App\Product::all()->random()->getkey(), 'samplings' => $newSamplings); $this->post('api/samplings/create', $request_body)->see('Created ' . count($newSamplings) . ' sampling(s)'); }
public function sort($tid, Request $request) { $sorts = BiliBiliHelper::getSorts(); //分类非法检测 if (!array_has($sorts, $tid)) { return $this->returnError('分类不存在'); } $order = $request->get('order', 'hot'); $page = $request->get('page', 1); //页码非法检测 if ($page < 1) { $page = 1; } //默认取出redis if ($order == 'hot' && $page == 1) { $redis = new Client(); $date = $redis->hget('update', 'sort'); $sort = $redis->hget('sort', $sorts[$tid]); $sort = json_decode($sort, true); } else { try { $request_array = ['tid' => $tid, 'order' => $order, 'page' => $page, 'pagesize' => 20]; $date = date('H:i:s'); $back = RequestUtil::getUrl(BiliBiliHelper::$SERVICE_URL . '/sort?' . http_build_query($request_array)); $sort = $back['content']; } catch (\Exception $e) { return $this->returnError('服务器君忙,待会再试吧...'); } } return view('sort')->with('content', $sort)->with('tid', $tid)->with('page', $page)->with('date', $date); }
/** * @param null $connection * @return bool * @throws \Exception */ public function send($connection = null) { $notifiers = Config::get('notifiers'); if (!is_null($connection) && array_has($notifiers, $connection)) { $notifiers = array_only($notifiers, [$connection]); } $factory = new NotifyMeFactory(); $successes = 0; foreach ($notifiers as $notifier) { if ($this->sender) { array_set($notifier, 'from', $this->sender); } $service = $factory->make($notifier); switch (array_get($notifier, 'driver')) { case 'hipchat': $response = $service->notify(array_get($notifier, 'room'), $this->message); break; default: throw new \Exception("Driver not yet supported."); } if ($response->isSent()) { $successes++; } else { throw new \Exception($response->message()); } } return $successes == count($notifiers); }
/** * @param array $data * * @return UserInterface */ public function updateUser(array $data) { if (array_has($data, "password")) { $data["password"] = bcrypt($data["password"]); } return $this->update($data); }
public function sort($tid, Request $request) { $sorts = BiliBiliHelper::getSorts(); //分类非法检测 if (!array_has($sorts, $tid)) { return $this->returnError('分类不存在'); } $order = $request->get('order', 'hot'); $page = $request->get('page', 1); //页码非法检测 $page = $page < 1 ? 1 : $page; if ($order == 'hot' && $page == 1) { $sort_list = Cache::get('sort_cache'); $date = Cache::get('refresh_time'); $sort = $sort_list[strval($tid)]; } else { try { $request_array = ['tid' => $tid, 'order' => $order, 'page' => $page, 'pagesize' => 20]; $date = date('H:i:s'); $back = RequestUtil::getUrl(BiliBiliHelper::$SERVICE_URL . '/sort?' . http_build_query($request_array)); $sort = $back['content']; } catch (\Exception $e) { return $this->returnError('服务器君忙,待会再试吧...'); } } return view('sort')->with('content', $sort)->with('tid', $tid)->with('page', $page)->with('date', $date); }
/** * CrudCommand constructor. */ public function handle() { $this->resource = str_replace(' ', '', $this->argument('resource')); $this->namespace = rtrim($this->getAppNamespace(), '\\'); $this->table_single = snake_case($this->resource); $this->table = str_plural($this->table_single); $this->single = str_replace('_', ' ', $this->table_single); $this->plural = str_plural($this->single); $options = $this->input->getOptions(); if (array_has($options, 'route-prefix') and $this->option('route-prefix')) { $this->route = $this->option('route-prefix') . '.' . $this->table_single; } else { $this->route = $this->table_single; } if (array_has($options, 'view-path') and $this->option('view-path')) { $this->view = $this->option('view-path') . '.' . $this->table_single; } else { $this->view = $this->table_single; } if (array_has($options, 'fields') and $this->option('fields')) { $this->fields = $this->getFields($this->option('fields')); } else { $this->fields = ''; } $this->variables = ['resource' => $this->resource, 'resource_plural' => str_plural($this->resource), 'namespace' => $this->namespace, 'table' => $this->table, 'table_single' => $this->table_single, 'single' => $this->single, 'single_capital' => ucwords($this->single), 'plural' => $this->plural, 'plural_capital' => ucwords($this->plural), 'route' => $this->route, 'view' => $this->view, 'fields' => $this->fields]; }
public function upload($request, $file) { $rand = Random::quick(20); if ($file) { $filename = $rand . "." . $file->getClientOriginalExtension(); $file->move('uploads', $filename); } else { if (array_has($request, 'file_url')) { $image = Image::make(array_get($request, 'file_url')); $mime = $image->mime(); //edited due to updated to 2.x if ($mime == 'image/jpeg') { $extension = '.jpg'; } elseif ($mime == 'image/png') { $extension = '.png'; } elseif ($mime == 'image/gif') { $extension = '.gif'; } else { $extension = ''; } $filename = $rand . $extension; $image->save(public_path('uploads/' . $filename)); } else { throw new Exception("NO IMAGE PROVIDED"); } } $data = ['filename' => $filename, 'scope' => array_get($request, 'scope'), 'scope_id' => array_get($request, 'scope_id')]; return $this->model->create($data); }
public function index() { if (Auth::check() || Auth::viaRemember()) { $itens = array(); $contents = unserialize(Storage::get('dashboard.dat')); if (array_has($contents, Auth::user()->company_id)) { $content = $contents[Auth::user()->company_id]; $accounts = $content['Accounts']; array_push($itens, array('class' => 'bg-blue', 'icon' => 'users', 'text' => 'Clientes', 'link' => 'accounts', 'lines' => array(0 => array('title' => 'Com Veículos', 'count' => $accounts[1] . ' / ' . $accounts[0], 'link' => 'accounts?hasvehicle=1&search=1', 'color' => 'primary'), 1 => array('title' => 'Sem Veículos', 'count' => $accounts[2] . ' / ' . $accounts[0], 'link' => 'accounts?hasvehicle=2&search=1', 'color' => 'danger')))); $vehicles = $content['Vehicles']; array_push($itens, array('class' => 'bg-blue', 'icon' => 'car', 'text' => 'Veículos', 'link' => 'vehicles', 'lines' => array(0 => array('title' => 'Com Rastreador', 'count' => $vehicles[1] . ' / ' . $vehicles[0], 'link' => 'vehicles?hasdevice=1&search=1', 'color' => 'primary'), 1 => array('title' => 'Sem Rastreador', 'count' => $vehicles[2] . ' / ' . $vehicles[0], 'link' => 'vehicles?hasdevice=2&search=1', 'color' => 'danger')))); $devices = $content['Devices']; array_push($itens, array('class' => 'bg-blue', 'icon' => 'tags', 'text' => 'Rastreadores', 'link' => 'devices', 'lines' => array(0 => array('title' => 'Em uso', 'count' => $devices[1] . " / " . $devices[0], 'link' => 'devices?hasvehicle=1&search=1', 'color' => 'primary'), 1 => array('title' => 'Disponíveis', 'count' => $devices[2] . " / " . $devices[0], 'link' => 'devices?hasvehicle=2&search=1', 'color' => 'success')))); $positions = $content['Positions']; array_push($itens, array('class' => 'bg-blue', 'icon' => 'map-marker', 'text' => 'Posições', 'link' => 'positions', 'lines' => array(0 => array('title' => 'Reportando', 'count' => $positions[1] . " / " . $positions[0], 'link' => 'positions', 'color' => 'primary'), 1 => array('title' => 'Não Reportando', 'count' => $positions[2] . " / " . $positions[0], 'link' => 'notReporting', 'color' => 'danger')))); } if (Auth::user()->isAccount() || Auth::user()->isUser()) { return view('home'); } $positioncontroller = new PositionsController(); $locations = $positioncontroller->dashboardMap(); return view('home', compact('itens', 'locations')); } else { return redirect('auth/login'); } }
public function import($data, $file) { $file = $this->upload->upload($file, 'files'); $newsletter_id = isset($data['newsletter_id']) && $data['newsletter_id'] > 0 ? $data['newsletter_id'] : null; if (!$file) { throw new \designpond\newsletter\Exceptions\FileUploadException('Upload failed'); } // path to xls $path = public_path('files/' . $file['name']); // Read uploaded xls $results = $this->read($path); // If the upload is not formatted correctly redirect back if (isset($results) && $results->isEmpty() || !array_has($results->toArray(), '0.email')) { throw new \designpond\newsletter\Exceptions\BadFormatException('Le fichier est vide ou mal formaté'); } // we want to import in one of the newsletter subscriber's list if ($newsletter_id) { // Subscribe the new emails $this->subscribe($results, $newsletter_id); // Store imported file as csv for mailjet sync $this->store($path); // Mailjet sync $this->sync($file['name'], $newsletter_id); } return $results; }
/** * @inheritdoc */ public function fill($attributes) { parent::fill($attributes); if ($this->isSensitive() && array_has($attributes, 'value')) { $this->value = Crypt::encrypt($this->value); } return $this; }
/** * @param $array * @param $key * @param null $default * @return mixed|null * Used for easily finding values in a FB Callback response */ public static function array_find($array, $key, $default = null) { if (array_has($array, $key)) { return array_get($array, $key); } else { return $default; } }
/** * @dataProvider array_remove_provider */ public function test_array_remove($path) { $array = []; array_set($array, $path, 'foo'); $this->assertTrue(array_has($array, $path)); array_remove($array, $path); $this->assertFalse(array_has($array, $path)); }
public function createComment(array $values) { if (!array_has($values, 'parent_id')) { return abort(404); } $values = array_only($values, Post::$editable); return $this->service->createComment($values); }
/** * Creates the new static instance with given values and returns it. * * @param array $fields * * @return static */ public static function with($fields = []) { $esewa = new static(); $esewa->order_id = array_get($fields, array_has($fields, 'id') ? 'id' : 'order_id'); $esewa->reference_id = array_get($fields, 'reference_id'); $esewa->amount = array_get($fields, 'amount'); return $esewa; }
/** * Store company. * * @param User $user * @param array $data * * @return Company|false */ public function store(User $user, array $data) { $company = new Company($data); $this->assignRepresentativeUser($company, $user); if (array_has($data, Company::LOGO_ID)) { $this->assignLogoById($company, $data[Company::LOGO_ID]); } return $this->update($company, $data); }
/** * Display the specified resource. * * @param Vote $vote * @return \Illuminate\Http\Response */ public function show(Vote $vote) { // $this->dispatch(new CloseVotingCommand($vote)); if (array_has(class_uses($vote->votable), EnrollableTrait::class)) { return view('project.vote.show')->with('model', $vote->votable); } $submissions = $vote->votable->submissions->load('user', 'votes'); return view('project.vote.show')->with('model', $vote->votable)->with('submissions', $submissions); }
/** * create * * @param array $data data * * @return UserInterface */ public function create(array $data) { $model = $this->createModel(); if (array_has($data, 'password')) { $data['passwordUpdatedAt'] = $model->freshTimestamp(); } $user = $model->create($data); return $user; }
public function setLocale($locale = 'en') { $locales = Config::get('app.locales', ['en' => 'English']); if (!array_has($locales, $locale)) { $locale = 'en'; } Cookie::queue('locale', $locale, 120); return redirect(url(URL::previous())); }
/** * @param string $style * @param string $string * @return string */ public function parseStyle($style, $string) { foreach ($this->getProcessingStylesRoutines() as $processing_styles_routine => $styles_array) { if (array_has($styles_array, $style)) { $string = preg_replace('/:style\\b/', $style, $string); } } return $string; }
private function parseSearchQuery() { $queries = $this->httpRequest->queries; $contentObject = App::make(ContentInterface::class); if (!count($queries) > 0) { return false; } if (array_has($queries, "page")) { $page = cache('pages')->filter(function ($cachedPage) use($queries) { return $cachedPage->url == $queries["page"]; })->first(); if (!$page) { $this->noSearchResult = true; } else { $tables = [(new ParsingContentFile())->getLayoutTableName($page->template->file)]; unset($queries['page']); } } else { $unique = cache('pages')->unique(function ($page) { return $page->template->file; }); foreach ($unique as $page) { $tables[] = (new ParsingContentFile())->getLayoutTableName($page->template->file); } } if ($this->noSearchResult) { return false; } $key = "search_"; foreach ($tables as $table) { $key .= $table . "_"; } foreach ($queries as $key => $val) { $key .= $key . "_" . $val . "_"; } if (cache()->has($key)) { return cache($key); } else { return cache()->remember($key, 1, function () use($tables, $contentObject, $queries) { $searchResult = new Collection(); foreach ($tables as $table) { $contentObject->setTable($table); foreach ($queries as $col => $val) { if ($col == "limit") { $val = (int) $val; $contentObject = $contentObject->search($col, $val); } else { $contentObject = $contentObject->search($col, $val); } } $searchResult = $searchResult->merge($contentObject->get()->all()); } return $searchResult; }); } }
public function update(array $input) { if (array_has($input, 'id')) { $id = $input['id']; $area = Area::find($id); $area->fill($input); $area->save(); return $area; } }
/** * Change formatting of text. * * @param $string * @param null $format * * @return string */ function cli_format($string, $format = null) { $formats = ['reset' => '0', 'bold' => '1', 'dark' => '2', 'italic' => '3', 'underline' => '4', 'blink' => '5', 'reverse' => '7', 'concealed' => '8']; if ($format === null or !array_has($formats, $format)) { return $string; } else { $format = $formats[$format]; } return s("[%sm%s[0m", $format, $string); }
/** * @param Request $request * @param $params * @param null $route * @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function executeSuccessHandler(Request $request, $params, $route = null) { if ($request->ajax()) { if (!array_has($params, 'target')) { $params = array_add($params, 'target', $route); } return $this->getJsonSuccessResponse($params); } return $this->handleSuccessWithFlashMessage($route); }
/** * @param $view */ public function compose(View $view) { $viewData = $view->getData(); $date = array_has($viewData, 'date') && $viewData['date'] ? $viewData['date'] : Carbon::today(); $calendar = $this->manager->getCalendar(Carbon::today()); $lastBillboard = $this->billboardsRepository->findNewer(); $view->with('calendar', $calendar); $view->with('date', $date); $view->with('lastBillboard', $lastBillboard); }
/** * returns hours for an employee * * @return array */ public function getEmployeeHours() { $result = []; foreach ($this->csv as $row) { if (array_has($row, 'ticket') && array_get($row, 'ticket') === '0') { $result[array_get($row, '__group__')] = array_get($row, 'Work_added', 0) + 0.0; } } return $result; }
/** * Get a subset of the items from the given array. DO NOT fill non-exist * keys with null. (different from array_only() function) * * @param array $array * @param array|string $keys * @return array */ function app_array_filter($array, $keys) { $results = []; foreach ($keys as $key) { if (array_has($array, $key)) { array_set($results, $key, array_get($array, $key)); } } return $results; }