本文整理汇总了PHP中Illuminate\Support\Facades\Event::listen方法的典型用法代码示例。如果您正苦于以下问题:PHP Event::listen方法的具体用法?PHP Event::listen怎么用?PHP Event::listen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Event
的用法示例。
在下文中一共展示了Event::listen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
public function boot()
{
Event::listen('backend.menu.extendItems', function ($manager) {
$manager->addSideMenuItems('Genius.Base', 'pages', ['contacts' => ['label' => 'genius.contacts::lang.settings.menu_label', 'icon' => 'icon-envelope-o', 'url' => Backend::url('genius/contacts/settings/update/1'), 'order' => 20]]);
$manager->addSideMenuItems('Genius.Base', 'admin', ['contacts' => ['label' => 'genius.contacts::lang.contacts.menu_label', 'icon' => 'icon-envelope-o', 'url' => Backend::url('genius/contacts/contacts'), 'order' => 20]]);
});
}
示例2: register_event_listener
private function register_event_listener()
{
$watch =& $this;
Event::listen('watcher:reload', function () use($watch) {
touch($watch->watcher_reload_file);
});
}
示例3: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__ . '/../config/profiler.php', 'profiler');
if (!$this->app->bound('hash')) {
$hash = $this->app->share(function () {
return new BcryptHasher();
});
$this->app->bind('hash', $hash);
}
$config = $this->app->make('config');
$enable = $config->get('app.debug');
$enable = boolval($enable);
$profilerRequest = $this->isProfilerCall();
/** @var Logger $logger */
$logger = $this->app->make('log');
try {
$profiler = ProfilerFactory::build($this->buildConfiguration($enable, $profilerRequest));
} catch (\Exception $e) {
$logger->error('Fail to build profiler error: ' . $e->getMessage(), [' message : ' => $e->getMessage(), ' file : ' => $e->getFile(), ' line : ' => $e->getLine(), ' trace : ' => $e->getTraceAsString()]);
$profiler = new NullProfiler();
}
if ($enable) {
if (!$profilerRequest) {
$logger->getMonolog()->pushHandler($profiler->getLogger());
}
$this->registerCors();
$this->registerRoutes();
}
$this->registerProfiler($profiler);
$profiler->initiate();
$profiler->getContext()->sendDebugIds();
Event::listen('kernel.handled', function () use($profiler) {
$profiler->terminate();
});
}
示例4: __construct
/**
* EventsDataSource constructor.
*/
public function __construct()
{
$this->points = [];
Event::listen('*', function () {
$this->points[] = ['memory' => memory_get_usage(true), 'time' => microtime(true)];
});
}
示例5: __construct
public function __construct()
{
$this->middleware('jwt.auth');
Event::listen('tymon.jwt.valid', function ($user) {
$this->user = $user;
});
}
示例6: registerListeners
/**
*
*/
protected function registerListeners()
{
EventFacade::listen('*', function ($param) {
$this->data[] = ['name' => EventFacade::firing(), 'param' => $param, 'time' => microtime(true)];
$this->stream();
});
}
示例7: listen
protected function listen(DataProvider $provider)
{
Event::listen(DataProvider::EVENT_FETCH_ROW, function (DataRow $row, DataProvider $provider) use($provider) {
if ($provider !== $provider) {
return;
}
$this->rows_processed++;
foreach ($this->fields as $field) {
$name = $field->getName();
$operation = $this->getFieldOperation($name);
switch ($operation) {
case self::OPERTATION_SUM:
$this->src[$name] += $row->getCellValue($field);
break;
case self::OPERATION_COUNT:
$this->src[$name] = $this->rows_processed;
break;
case self::OPERATION_AVG:
if (empty($this->src["{$name}_sum"])) {
$this->src["{$name}_sum"] = 0;
}
$this->src["{$name}_sum"] += $row->getCellValue($field);
$this->src[$name] = round($this->src["{$name}_sum"] / $this->rows_processed, 2);
break;
default:
throw new Exception("TotalsRow:Unknown aggregation operation.");
}
}
});
}
示例8: boot
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
* @return void
*/
public function boot(DispatcherContract $events)
{
parent::boot($events);
Event::listen('Aacotroneo\\Saml2\\Events\\Saml2LoginEvent', function (Saml2LoginEvent $event) {
$user = $event->getSaml2User();
/*$userData = [
'id' => $user->getUserId(),
'attributes' => $user->getAttributes(),
'assertion' => $user->getRawSamlAssertion()
];*/
$laravelUser = User::where("username", "=", $user->getUserId())->get()->first();
if ($laravelUser != null) {
Auth::login($laravelUser);
} else {
//if first user then create it and login
$count = \App\User::all()->count();
if ($count == 0) {
$data = array();
$data['lastname'] = "";
$data['firstname'] = "";
$data['username'] = $user->getUserId();
$data['role'] = "admin";
$user = \App\User::create($data);
\Auth::login($user);
return \Redirect::to('/');
} else {
abort(401);
}
}
//if it does not exist create it and go on or show an error message
});
}
示例9: boot
public function boot()
{
Event::listen('illuminate.query', function ($query, $params, $time, $conn) {
Log::info($query);
});
$this->app['router']->post('datagridview', '\\mkdesignn\\datagridview\\DataGridViewController@postIndex');
}
示例10: register
/**
* Register the service provider.
*/
public function register()
{
App::bind('toolbox.commands.controllers', function () {
return new \Impleri\Toolbox\Commands\ControllersCommand();
});
App::bind('toolbox.commands.models', function () {
return new \Impleri\Toolbox\Commands\ModelsCommand();
});
App::bind('toolbox.commands.routes', function () {
return new \Impleri\Toolbox\Commands\RoutesCommand();
});
App::bind('toolbox.commands.schema', function () {
return new \Impleri\Toolbox\Commands\SchemaCommand();
});
App::bind('toolbox.commands.views', function () {
return new \Impleri\Toolbox\Commands\ViewsCommand();
});
App::bind('toolbox.commands.build', function () {
return new \Impleri\Toolbox\Commands\BuildCommand();
});
$this->commands($this->provides());
// Subscribe our own commands to toolbox.compile
Event::listen('toolbox.build', function ($app) {
$app->call('toolbox:routes');
$app->call('toolbox:controllers');
$app->call('toolbox:models');
$app->call('toolbox:schema');
$app->call('toolbox:views');
});
}
示例11: boot
/**
* Register the application's event listeners.
*
* @return void
*/
public function boot()
{
$add_hook = function ($type, $name, $listeners) {
$listeners = is_array($listeners) ? $listeners : [$listeners];
array_walk($listeners, function ($listener) use($type, $name) {
$fn = 'add_' . $type;
// `add_action` or `add_filter`
$fn($name, function () use($listener) {
$listener_instance = app()->make($listener);
return call_user_func_array([$listener_instance, 'handle'], func_get_args());
}, 10, 10);
});
};
foreach ($this->listens() as $event => $listeners) {
$listeners = is_array($listeners) ? $listeners : [$listeners];
foreach ($listeners as $listener) {
Event::listen($event, $listener);
}
}
foreach ($this->subscribe as $subscriber) {
Event::subscribe($subscriber);
}
foreach ($this->action as $action => $listeners) {
$add_hook('action', $action, $listeners);
}
foreach ($this->filter as $filter => $listeners) {
$add_hook('filter', $filter, $listeners);
}
}
示例12: register
/**
* Register the application services.
*
* @return void
*/
public function register()
{
$configPath = __DIR__ . '/../config/sql-logging.php';
$this->mergeConfigFrom($configPath, 'sql-logging');
if (config('sql-logging.log', false)) {
Event::listen('illuminate.query', function ($query, $bindings, $time) {
$data = compact('bindings', 'time');
// Format binding data for sql insertion
foreach ($bindings as $i => $binding) {
if ($binding instanceof \DateTime) {
$bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
} else {
if (is_string($binding)) {
$bindings[$i] = "'{$binding}'";
}
}
}
// Insert bindings into query
$query = str_replace(array('%', '?'), array('%%', '%s'), $query);
$query = vsprintf($query, $bindings);
$log = new Logger('sql');
$log->pushHandler(new StreamHandler(storage_path() . '/logs/sql-' . date('Y-m-d') . '.log', Logger::INFO));
// add records to the log
$log->addInfo($query, $data);
});
}
}
示例13: __construct
public function __construct()
{
parent::__construct();
Route::get('partners', array('before' => 'auth', array($this, 'view')));
Event::listen('construct_left_menu', array($this, 'left_menu_item'));
$this->layout = Template::mainLayout();
}
示例14: run
/**
* Main processing loop
*
* @throws \ZMQPollException
*/
public function run()
{
$poll = new \ZMQPoll();
$readable = $writable = [];
foreach ($this->listen as $socket) {
$poll->add($socket, \ZMQ::POLL_IN);
}
$processing = true;
Event::listen('zeroevents.service.stop', function () use(&$processing) {
$processing = false;
});
while ($processing) {
try {
$poll->poll($readable, $writable, $this->pollTimeout);
foreach ($readable as $socket) {
$socket->pullAndFire();
}
} catch (\ZMQPollException $ex) {
if ($ex->getCode() == 4) {
// 4 == EINTR, interrupted system call
usleep(1);
// Don't just continue, otherwise the ticks function won't be processed
continue;
}
throw $ex;
}
if (!$readable) {
Event::fire('zeroevents.service.idle', $this);
}
}
}
示例15: execute
/**
* Method for evaluating the PHP's code.
*
* @param string $code - PHP's code that we want to evaluate
* @return string
*/
public function execute($code = '')
{
// if argument is given then we override code that has been set on the constructor.
if (strlen($code) > 0) {
$this->code = $code;
}
$me = $this;
// listen to the laravel query event
Event::listen('illuminate.query', function ($query, $bindings, $time, $name) use($me) {
$me->addQuery($query, $bindings, $time, $name);
});
// start output buffering
ob_start();
// OK, this is the time...
$start = microtime(TRUE);
$retval = @eval($this->code);
$end = microtime(TRUE);
$this->execTime = $end - $start;
// if the eval() return FALSE then it could be syntax error.
if ($retval === FALSE) {
throw new Exception("I can not evaluate your code, it could be syntax error or " . "you're drunk. Please check your code or make some coffee.");
}
// collect memory usage
$this->memory = array('current' => memory_get_usage(TRUE), 'peak' => memory_get_peak_usage(TRUE));
// catch the output buffer that we getting from eval() above
$this->output = ob_get_clean();
return $this->render();
}