标签:laravel
<?php namespace Illuminate\Console; use Closure; // namespace trait ConfirmableTrait { /** * Confirm before proceeding with the action. * * @param string $warning * @param \Closure|bool|null $callback * @return bool */ public function confirmToProceed($warning = ‘Application In Production!‘, $callback = null) { $callback = is_null($callback) ? $this->getDefaultConfirmCallback() : $callback;// set the callback $shouldConfirm = $callback instanceof Closure ? call_user_func($callback) : $callback; // check the confirm is the instance of the Closure. if ($shouldConfirm) {// the right confirm if ($this->option(‘force‘)) { return true; }// has a key to said be ‘fore‘ $this->comment(str_repeat(‘*‘, strlen($warning) + 12));// set the comment string $this->comment(‘* ‘.$warning.‘ *‘);// increment the $this->comment(str_repeat(‘*‘, strlen($warning) + 12));// get the * $this->output->writeln(‘‘);// use a function to be $confirmed = $this->confirm(‘Do you really wish to run this command? [y/N]‘); // set the confirm way if (! $confirmed) { $this->comment(‘Command Cancelled!‘); return false; }// get } return true; }// confirm before the action be run /** * Get the default confirmation callback. * * @return \Closure */ protected function getDefaultConfirmCallback() { return function () { return $this->getLaravel()->environment() == ‘production‘; }; }// Get the default confirmation }
本文出自 “专注php” 博客,请务必保留此出处http://jingshanls.blog.51cto.com/3357095/1763665
每天laravel-20160715|ConfirmableTrait
标签:laravel
原文地址:http://jingshanls.blog.51cto.com/3357095/1763665