本文整理汇总了PHP中array_has函数的典型用法代码示例。如果您正苦于以下问题:PHP array_has函数的具体用法?PHP array_has怎么用?PHP array_has使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_has函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$filename = $this->argument('filename');
$stream = fopen($filename, 'r');
$this->user = User::whereEmail('bot@quoterr.me')->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);
}
}
示例2: with
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;
}
示例3: __construct
public function __construct($options = [])
{
if (!array_has($options, 'redirectUri')) {
$options['redirectUri'] = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
}
parent::__construct($options);
}
示例4: getExcerptAttribute
/**
* 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;
}
示例5: testSamplingCreationWithPost
/**
* 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)');
}
示例6: sort
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);
}
示例7: send
/**
* @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);
}
示例8: updateUser
/**
* @param array $data
*
* @return UserInterface
*/
public function updateUser(array $data)
{
if (array_has($data, "password")) {
$data["password"] = bcrypt($data["password"]);
}
return $this->update($data);
}
示例9: sort
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);
}
示例10: handle
/**
* 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];
}
示例11: upload
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);
}
示例12: index
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');
}
}
示例13: import
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;
}
示例14: fill
/**
* @inheritdoc
*/
public function fill($attributes)
{
parent::fill($attributes);
if ($this->isSensitive() && array_has($attributes, 'value')) {
$this->value = Crypt::encrypt($this->value);
}
return $this;
}
示例15: array_find
/**
* @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;
}
}